How to change UIAlertController button text colour in iOS9?

后端 未结 14 1372
隐瞒了意图╮
隐瞒了意图╮ 2020-12-15 16:16

The question is similar to iOS 8 UIActivityViewController and UIAlertController button text color uses window's tintColor but in iOS 9.

I have a UIAlertControlle

14条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-15 16:44

    In Swift 2.2 you can use following code

     // LogOut or Cancel
        let logOutActionSheet: UIAlertController = UIAlertController(title: "Hello Mohsin!", message: "Are you sure you want to logout?", preferredStyle: .Alert)
    
        self.presentViewController(logOutActionSheet, animated: true, completion: nil)
    
        let cancelActionButton: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in
            print("Cancel Tapped")
        }
    
        logOutActionSheet.addAction(cancelActionButton)
    
        let logOutActionButton: UIAlertAction = UIAlertAction(title: "Clear All", style: .Default)
        { action -> Void in
            //Clear All Method
            print("Logout Tapped")
    
        }
    
        logOutActionButton.setValue(UIColor.redColor(), forKey: "titleTextColor")
    
        logOutActionSheet.addAction(logOutActionButton)
    

提交回复
热议问题