2017-07-28 60 views
0

我試圖更改UIAction表「取消」按鈕的背景顏色,但它不起作用。 這裏是我的代碼片段如何更改UIAction表取消按鈕背景顏色

if let subview = alertController.view.subviews.first, let alertContentView = subview.subviews.first { 
    for innerView in alertContentView.subviews { 
     innerView.backgroundColor = UIColor.red//StyleKit.popoverDefaultBackgroundColor 
     //drop shadow 
     innerView.layer.masksToBounds = false 
     innerView.layer.shadowOpacity = 0.8 
    } 
} 
let subview = alertController.view.subviews.last! as UIView 
let alertContentView = subview.subviews.last! as UIView 
alertContentView.backgroundColor = UIColor.black 

let cancelAction = UIAlertAction(title: "Cancel".localize(), style: .cancel) 

alertController.addAction(changeAction) 
alertController.addAction(cancelAction) 
+0

首先參考以下鏈接 https://stackoverflow.com/questions/30287400/change-uiactionsheet-buttons-background-color-and - 按鈕的字體 – shahnilay86

回答

0

試試這個 - let subView = alertController.view.subviews.first! Var alertContentView = subView.subviews.first! alertContentView.backgroundColor = UIColor.black alertContentView.layer.cornerRadius = 5

相關問題