AlertController with white borders
I've created an alert dispatcher with an action sheet and two buttons. Since the worksheet will have rounded edges, white appears at the four corners of the screen. I tried changing the background color in the alertcontroller, but that makes the action sheet rectangular with a sharp border instead of rounded borders. I tried setting the background color of the view to clear the color Tried setting the border radius as well. Here's my action sheet. I want these white edges to be invisible.
Also how to change the background color Cancel.
let cancelAction = UIAlertAction(title: "Cancel".localize(), style: .cancel) { _ in
// this is where I am creating the cancelAction
}
Edit - 1: Add code for 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)
}
source to share
here is the solution to this white border 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)
Update with hexadecimal color
Github: https://github.com/BhaveshDhaduk/AlertControllerSwift
source to share