我的UIAlertController
首选格式ActionSheet
运行良好,没有任何问题。为了防止冗长的代码墙,我删除了UIAlertAction
闭包中的操作并添加了代码:
let alert = UIAlertController(title: "More actions", message: nil, preferredStyle: .ActionSheet)
//alert.view.tintColor = UIColor(red: CGFloat(252.0/255.0), green: CGFloat(112.0/255.0), blue: CGFloat(87.0/255.0), alpha: 1.0)
alert.addAction(UIAlertAction(title: "Rename", style: .Default, handler: { (action: UIAlertAction!) -> Void in }))
alert.addAction(UIAlertAction(title: "Move", style: .Default, handler: { (action: UIAlertAction!) -> Void in }))
alert.addAction(UIAlertAction(title: "Keep offline", style: .Default, handler: { (action: UIAlertAction!) -> Void in }))
alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
此代码工作正常,结果如下:
然而当我取消注释我设置tintColor
的行时,我的.Default
按钮与.Cancel
按钮之间的距离会缩小:< / p>
有没有办法防止这种情况发生,或者是否是我忽略的一些微小细节的结果?
答案 0 :(得分:2)
将按钮添加到警报控制器后设置色调颜色似乎有效:
let alert = UIAlertController(title: "More actions", message: nil, preferredStyle: .ActionSheet)
alert.addAction(UIAlertAction(title: "Rename", style: .Default, handler: { (action: UIAlertAction!) -> Void in }))
alert.addAction(UIAlertAction(title: "Move", style: .Default, handler: { (action: UIAlertAction!) -> Void in }))
alert.addAction(UIAlertAction(title: "Keep offline", style: .Default, handler: { (action: UIAlertAction!) -> Void in }))
alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
alert.view.tintColor = UIColor(red: CGFloat(252.0/255.0), green: CGFloat(112.0/255.0), blue: CGFloat(87.0/255.0), alpha: 1.0)
self.presentViewController(alert, animated: true, completion: nil)
答案 1 :(得分:2)
需要在样式设置后设置警报视图色调。