kri*_*hna 3 ios swift uialertcontroller
我创建了一个带有操作表和两个按钮的警报控制器。由于操作表将具有圆形边缘,因此在屏幕上的四个角上会出现白色。我尝试更改警报控制器的背景颜色,但这使操作表成为具有锐边边框而不是圆形边框的矩形。我尝试将视图背景颜色设置为清晰颜色也尝试设置边框半径。这是我的行动表。我希望这些白色边缘不可见。
另外,如何更改取消的背景颜色。
let cancelAction = UIAlertAction(title: "Cancel".localize(), style: .cancel) { _ in
// this is where I am creating the cancelAction
}
Run Code Online (Sandbox Code Playgroud)
编辑 - 1:添加警报控制器代码
func showActionSheet(_ changeAction: UIAlertAction) {
let alertController = UIAlertController(title: "", message: "Here is my alert text".localize(), preferredStyle: .actionSheet)
alertController.view.tintColor = StyleKit.goldenColor
let attributedString = NSAttributedString(string: alertController.message!, attributes: [
NSForegroundColorAttributeName : StyleKit.whiteColor
])
alertController.setValue(attributedString, forKey: "attributedMessage")
if let subview = alertController.view.subviews.first, let alertContentView = subview.subviews.first {
for innerView in alertContentView.subviews {
innerView.backgroundColor = StyleKit.popoverDefaultBackgroundColor
}
}
let cancelAction = UIAlertAction(title: "Cancel".localize(), style: .cancel) { _ in
self.doneButton.isEnabled = true
}
alertController.addAction(changeAction)
alertController.addAction(cancelAction)
self.present(alertController, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
这是这个白色边框的解决方案UIAlertAction actionSheet
let actionSheet = UIAlertController.init(title: nil, message: nil, preferredStyle: .actionSheet)
if let subview = actionSheet.view.subviews.first, let actionSheet = subview.subviews.first {
for innerView in actionSheet.subviews {
innerView.backgroundColor = .purple
innerView.layer.cornerRadius = 15.0
innerView.clipsToBounds = true
}
}
actionSheet.addAction(UIAlertAction.init(title: "Take Photo", style: UIAlertActionStyle.default, handler: { (action) in
}))
actionSheet.addAction(UIAlertAction.init(title: "Choose Photo", style: UIAlertActionStyle.default, handler: { (action) in
}))
actionSheet.addAction(UIAlertAction.init(title: "Cancel", style: UIAlertActionStyle.cancel, handler: { (action) in
}))
actionSheet.view.tintColor = .orange
self.present(actionSheet, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
使用十六进制颜色更新
Github: https: //github.com/BhaveshDhaduk/AlertControllerSwift
| 归档时间: |
|
| 查看次数: |
1923 次 |
| 最近记录: |