mardi 4 décembre 2018

How to check image on navigation bar button loaded programatically

I am loading a button on right navigation item programmatically. Then i call a function to check the current image. This function basically turns on the flash but some how ots not going inside the if condition. my code is

 @objc func flashOnOff(sender: UIButton!) {
    print("Flash button press")
    //        let flashsetting = AVCapturePhotoSettings()
    guard (currentDevice?.isTorchAvailable)! else {return}


    do {
        try currentDevice?.lockForConfiguration()
        if flashButton.currentImage == UIImage(named: "FlashOffIcon.png")
        {

           flashButton.setImage(#imageLiteral(resourceName: "Flash On Icon").withRenderingMode(.alwaysOriginal), for: .normal)
            navigationItem.rightBarButtonItem = UIBarButtonItem(customView: flashButton)

            //            flashButton.clipsToBounds = true
            currentDevice?.torchMode = .on
            flashonindicator = 1
        }
        else
        {
            flashButton.setImage(#imageLiteral(resourceName: "FlashOffIcon").withRenderingMode(.alwaysOriginal), for: .normal)
            navigationItem.rightBarButtonItem = UIBarButtonItem(customView: flashButton)
            currentDevice?.torchMode = .off
            flashonindicator = 0
        }
    }
    catch{
        debugPrint(Error.self)
    }
}

Any idea?

Aucun commentaire:

Enregistrer un commentaire