如何检查多个图像!=无 [英] how to check for multiple images != nil

查看:53
本文介绍了如何检查多个图像!=无的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用if语句和&& 运算符检查是否有多个UIImageView != nil ,但是问题是,当用户选择任何UIImageView的照片时,3 driverPImg.image!= nil&&passImg.image!=无&&carImg.image!= nil 下一条代码被提取,它将不检查其余条件

I am trying to check if multiple UIImageView != nil using if statement and && operator but the problem is that when the user pick any photo of the 3 driverPImg.image != nil && passImg.image != nil && carImg.image != nil the next code exuted and it will not check for the rest conditions

此图像显示3幅图像排列成水平,在Btn将颜色更改为红色之前,所有这些图像均应填充为零或为零,但未发生应该发生的事情

this image shows 3 images line up Horizontally all those images should be filled or not nil before the Btn change color to red but what it suppose to happen didn't happen

extension VC: UINavigationControllerDelegate, UIImagePickerControllerDelegate {
    
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
            
        if let editedImg = info[.editedImage] as? UIImage {
            
            SelectedImg = editedImg.withRenderingMode(.alwaysOriginal)
            
        } else if let originalImg = info[.originalImage] as? UIImage {
            SelectedImg = originalImg.withRenderingMode(.alwaysOriginal)
            
        }
        
        if let image = SelectedImg {
            if pictureSelectionType == .profilePicture {
                driverPImg.image = image
                
            }else if pictureSelectionType == .idPicture{
                passImg.image = image
                
            }else if pictureSelectionType == .vhiclePicture{
                carImg.image = image
                
            }else {
                backCarImg.image = image
                
            }

            if driverPImg.image != nil && passImg.image != nil && carImg.image != nil{
                sendApplyBtn.backgroundColor = UIColor.delevareColor
            }else {
                sendApplyBtn.backgroundColor = UIColor.lightGray
            }
            
            
        }
        dismiss(animated: true, completion: nil)
    }
        
    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        self.dismiss(animated: true, completion: nil)
    }
    
}

推荐答案

您可以使用占位符进行检查,这意味着您的占位符图像是否称为"placeHolder.png"

you can check it by using your placeholder, which means if your placeholder image called "placeHolder.png"

if driverPImg.image == UIImage(named: "placeHolder.png") && passImg.image == UIImage(named: "placeHolder.png") && carImg.image == UIImage(named: "placeHolder.png") {
sendApplyBtn.backgroundColor = UIColor.lightGray

            }else {
                  sendApplyBtn.backgroundColor = UIColor.delevareColor
            }

这篇关于如何检查多个图像!=无的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆