I'm trying to achieve something like this:
I'm follwing this Question's answer: Change background color of Cancel button for action sheet
and so far using the answer I have achived this:
But this is only working upto IOS 11, When I run the app on IOS 12.2 emulator the cancel button didn't separate from other buttons.
Here you can see:
I wanted to ask is it a latest IOS bug or Am I missing something for latest IOS?
Here is my Code:
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
alertController.addAction(UIAlertAction(title: "Weekly View", style: .default, handler: nil))
alertController.addAction(UIAlertAction(title: "Monthly View", style: .default, handler: nil))
if let firstSubview = alertController.view.subviews.first, let alertContentView = firstSubview.subviews.first {
for view in alertContentView.subviews {
view.backgroundColor = .blue
}
}
alertController.view.tintColor = UIColor(red: 1.0, green: 0.2, blue: 0.33, alpha: 1)
let cancelButtonViewController = CancelButtonViewController()
let cancelAction = UIAlertAction(title: "", style: .cancel, handler: nil)
cancelAction.setValue(cancelButtonViewController, forKey: "contentViewController")
alertController.addAction(cancelAction)
present(alertController, animated: true, completion: nil)
And CancelButtonViewController code:
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .green
let buttonText = UILabel()
buttonText.text = "Cancel"
buttonText.font = UIFont(name: "AppleSDGothicNeo-Regular", size: 20)
buttonText.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(buttonText)
buttonText.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
buttonText.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
}
And one thing more I'm also getting a Constraints error by default whenever I create AlertView with .actionSheet style. Maybe that could be the reason. I have done some research and found this post in this post they suggested to ignore this error.
Error:
I hope my question didn't irritate you. As I'm a noob in IOS programming. Thanks