0
My question is similar to this where I couldn't find the answer.
UIAlertController change background color of Cancel button for action sheet 這alertController with white borders 我想actionStyle取消按鈕爲「取消」的背景應該是不同的顏色(默認情況下,這將是白色)。如何更改取消按鈕的背景顏色。我不想將actionStyle更改爲默認值。有沒有其他方法可以實現這一點? 這是我的代碼UIAlertController取消操作的背景色
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)
}
你想改變「取消」動作的字體顏色? –
在其中一個問題的答案有一個黑客,但我更願意創建我的自定義警報。 https://stackoverflow.com/a/44721186/1031944 –
我想要更改取消操作的背景顏色。不是字體或文本(取消)。 @SamarthKejriwal – vinny