2017-04-03 14 views
0

UIAlertControllerに問題があります。背景色が正しく表示されません。どうすればよろしいですか?UIAlertAction背景色

これはコードです:

let alert = UIAlertController(title: "Choose qty", message: "", preferredStyle: UIAlertControllerStyle.alert) 
let pickerController = PickerQtyController() 
alert.setValue(pickerController, forKey: "contentViewController") 
// Testing color 
alert.view.tintColor=UIColor.blue 
let backView = alert.view.subviews.last?.subviews.last 
backView?.layer.cornerRadius = 10.0 
backView?.backgroundColor = UIColor.blue 
// Btns 
let saveBtn = UIAlertAction(title: "Save", style: UIAlertActionStyle.default) { 
    UIAlertAction in 
    print("UIAlertController: Saved") 
    pickerController.saveNewValueOfPicker() 
} 
let cancelBtn = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel) { 
    UIAlertAction in 
    print("UIAlertController: Canceled") 
} 
alert.addAction(saveBtn) 
alert.addAction(cancelBtn) 
self.present(alert, animated: true) 

ありがとうございました!

+1

そのようなUIAlertControllerを悪用しないでください。ビューを作成し、カスタムビューコントローラーを介して表示します。 – matt

答えて

2

それは醜いと間違ったデザインです。カスタムビューコントローラを作成し、その中に選択コントローラを追加する必要があります。背景を透明に変更し、モーダルプレゼンテーションスタイルを現在のコンテキストに設定して、カスタムビューコントローラを表示します。

self.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext