1
UIImage가 포함 된 단추를 만들려면이 코드를 작성했습니다.템플릿 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가 붉은 색으로 돌아옵니다. 경고가 표시 될 때도 이미지가 빨간색으로 유지되고 화면의 나머지 부분은 약간 어두워지기를 바랍니다. 어떻게해야합니까?
답장을 보내 주셔서 감사합니다. 하지만 내 질문은 이미이 링크에서 해결되었습니다 https://stackoverflow.com/questions/46817243/how-to-prevent-ios-decolorize-image-below-a-popover-alert – Thiago