gpt4 book ai didi

ios - 模板 UIImage 改变颜色

转载 作者:行者123 更新时间:2023-11-29 11:38:30 29 4
gpt4 key购买 nike

<分区>

我写这段代码是为了创建一个按钮,里面有一个 UIImage。

func createDrawerBarButton(image : String) {

let button = UIButton(type: .custom)
button.setImage(UIImage(named: image)?.withRenderingMode(.alwaysTemplate), for: UIControlState.normal)

button.frame = CGRect(x: 0, y: 0, width: 35, height: 35)
button.tintColor = UIColor(red: 208/255, green: 33/255, blue: 33/255, alpha: 1.0)
button.addTarget(self, action: #selector(self.drawerClicked(_:)), for: UIControlEvents.touchUpInside)

let barButton = UIBarButtonItem(customView: button)
self.navigationItem.leftBarButtonItem = barButton

}

当我点击按钮时,它会调用一个显示警报的方法。这是方法:

func drawerClicked(_ sender: Any) {
let cancelAction = UIAlertAction(title: "Cancel", style: .default, handler: nil)
let wifiAction = UIAlertAction(title: "Wi-Fi", style: .default) { (UIAlertAction) in
let url = URL(string: "App-Prefs:root=WIFI")
UIApplication.shared.openURL(url!)
}

let alert = UIAlertController(title: "Wi-Fi)", message: "Please, connect your WI-FI", preferredStyle: .alert)

alert.addAction(cancelAction)
alert.addAction(wifiAction)
self.present(alert, animated: true, completion: nil)
}

效果很好,但是当对话框出现时,我的 UIImage 改变了颜色。红色变成灰色。关闭对话框后,UIImage 恢复为红色。我希望该图像即使在出现警报时也保持红色,只是比屏幕的其余部分稍暗。我该怎么做?

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com