2015-07-10 49 views
2

我有我的UIAlertController,首選樣式ActionSheet可以正常工作,沒有任何問題。爲了防止代碼冗長的牆上,我已經刪除了UIAlertAction關閉的動作和我添加代碼:UIAlertController(ActionSheet)在設置tintColor後更改形狀

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) 

此代碼工作正常,並導致成這樣:

enter image description here

然而當我取消註釋我設置tintColor的行時,我失去了我的.Default按鈕和.Cancel按鈕之間的差距:

enter image description here

有沒有辦法來防止這種情況的發生,或者這是否是我忽視的一些微小細節的後果?

+0

奇怪的肯定。問題是,如果您在設置其他按鈕之後設置了色調顏色,默認是否仍然會發生? – Aggressor

+0

我沒有想到這一點。有用! – Michal

+1

雅它愚蠢的,你甚至不得不這樣做,它的蘋果部分 – Aggressor

回答

2

警報視圖色調需要的造型後進行設置。

+0

我會將您的答案標記爲已接受,因爲即使它在評論中,您也是第一個回答。 (備查) – Michal

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) 
+0

確實如此! – Michal