[英]UIAlertController change background color of Cancel button for action sheet
[英]UIAlertController Cancel action background color
My question is similar to this where I couldn't find the answer.
UIAlertController更改操作表的“取消”按鈕的背景顏色,並帶有白色邊框的alertController我希望將actionStyle的“取消”按鈕設置為“取消”,並且背景應為不同的顏色(默認情況下為白色)。 如何更改“取消”按鈕的背景顏色。 我不想將actionStyle更改為默認值。 還有其他方法可以做到這一點嗎? 這是我的代碼
func showActionSheet(_ changeAction: UIAlertAction) {
let alertController = UIAlertController(title: "", message: "Are you sure".localize(), preferredStyle: .actionSheet)
alertController.view.tintColor = UIColor.green
if let subview = alertController.view.subviews.first, let alertContentView = subview.subviews.first {
for innerView in alertContentView.subviews {
innerView.backgroundColor = UIColor.red
}
}
let cancelAction = UIAlertAction(title: "Cancel".localize(), style: .cancel) { _ in
self.doneButton.isEnabled = true
}
alertController.addAction(changeAction)
alertController.addAction(cancelAction)
self.present(alertController, animated: true)
}
可以使用UIAppearance和一點技巧對其進行更改。 在這里查看我的答案
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.