我可以改变颜色UIAlertController吗?标准颜色是蓝色.它与标准的iOS应用程序非常接近.如果它是可定制的?我怎样才能改变这个颜色?例如按钮颜色.
谢谢!
gui*_*dev 17
您可以更改tintColor底层视图,但是,由于iOS 9中引入的已知错误(https://openradar.appspot.com/22209332),tintColor被应用程序窗口覆盖tintColor.
你可以:
tintColor在AppDelegate中更改应用程序.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
self.window.tintColor = UIColor.redColor()
return true
}
Run Code Online (Sandbox Code Playgroud)重新应用完成块中的颜色.
self.presentViewController(alert, animated: true, completion: {() -> Void in
alert.view.tintColor = UIColor.redColor()
})
Run Code Online (Sandbox Code Playgroud)小智 9
在Swift中,你可以这样做:
let alert = UIAlertController(title: "Alert", message: "This is an alert.", preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
alert.view.tintColor = UIColor.redColor()
self.presentViewController(alert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
在Swift 4和Xcode 9.2中
let alertView = UIAlertController(title: "", message: "", preferredStyle: .alert)
alertView.addAction(UIAlertAction(title: "CONFIRM", style: .default, handler: { (alertAction) -> Void in
//my logic
}))
alertView.addAction(UIAlertAction(title: "CANCEL", style: .default, handler: nil))
alertView.view.tintColor = UIColor.init(red: 45.0/255.0, green: 187.0/255.0, blue: 135.0/255.0, alpha: 1.0)
present(alertView, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8492 次 |
| 最近记录: |