带有白色边框的 alertController
alertController with white borders
我创建了一个带有操作 sheet 和两个按钮的警报控制器。由于 actionsheet 将具有圆角边缘,在屏幕上,在四个角上,会出现白色。我尝试更改 alertcontroller 的背景颜色,但那会使操作 sheet 变为具有锐边而不是圆形边框的矩形。我尝试将视图背景颜色设置为清除颜色
也尝试设置边界半径。
这是我的操作 sheet。我希望那些白边不可见。
还有,如何更改取消的背景颜色。
let cancelAction = UIAlertAction(title: "Cancel".localize(), style: .cancel) { _ in
// this is where I am creating the cancelAction
}
编辑 - 1:为 alertcontroller 添加代码
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)
}
这里是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)
更新为十六进制颜色
Github : https://github.com/BhaveshDhaduk/AlertControllerSwift
我创建了一个带有操作 sheet 和两个按钮的警报控制器。由于 actionsheet 将具有圆角边缘,在屏幕上,在四个角上,会出现白色。我尝试更改 alertcontroller 的背景颜色,但那会使操作 sheet 变为具有锐边而不是圆形边框的矩形。我尝试将视图背景颜色设置为清除颜色 也尝试设置边界半径。 这是我的操作 sheet。我希望那些白边不可见。
还有,如何更改取消的背景颜色。
let cancelAction = UIAlertAction(title: "Cancel".localize(), style: .cancel) { _ in
// this is where I am creating the cancelAction
}
编辑 - 1:为 alertcontroller 添加代码
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)
}
这里是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)
更新为十六进制颜色
Github : https://github.com/BhaveshDhaduk/AlertControllerSwift