【问题标题】:How to change the specific button text colour programmatically in the UIAlertController如何在 UIAlertController 中以编程方式更改特定按钮文本颜色
【发布时间】:2015-06-01 05:27:36
【问题描述】:

我想将 UIAlertController 中“取消”按钮的颜色更改为橙​​色,并保持“注销”按钮的颜色不变。我附上了下面的警报控制器的屏幕截图和代码。

警报视图的代码

alert = UIAlertController(title: "", message: "Are you sure you want to log out?", preferredStyle: UIAlertControllerStyle.Alert)
    alert.view.tintColor = UIColor.blackColor()
    alert.addAction(UIAlertAction(title: "Log out", style: UIAlertActionStyle.Cancel, handler:{ (UIAlertAction)in

        println("Log Out button clicked.")

        prefs.setBool(false, forKey: "Isloggedin")
        NSUserDefaults.resetStandardUserDefaults()
        prefs.setBool(true, forKey: "IsEmail")
        prefs.setObject(email, forKey: "loggedemail")
        prefs.synchronize()
        let mainview = self.storyboard?.instantiateViewControllerWithIdentifier("mainscreen") as! mainViewController

        self.navigationController?.pushViewController(mainview, animated: true)
    }))

    //alert.view.tintColor = UIColor.yellowColor()
    alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default, handler:{ (UIAlertAction)in
        println("Cancel button clicked.")
    }))

    self.presentViewController(alert, animated: true, completion: {
        println("completion block.")


    })

【问题讨论】:

    标签: swift uialertcontroller


    【解决方案1】:

    我创建了一个自定义警报,我们可以在其中根据我们的要求进行更改。

    我已附上 GitHub Link

    【讨论】:

      猜你喜欢
      • 2021-09-27
      • 1970-01-01
      • 2010-12-21
      • 2015-02-02
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 2019-05-20
      • 1970-01-01
      相关资源
      最近更新 更多