I am using a rounded UIButton for my login screen, when the user click the login button I do my login process if something went wrong I show an alert but after showing it the button changes it background for its own.
I set te background color from the storyboard.
I use a custom UIButton class to add the corners and shadow to the button.
class RoundedShadowButton: UIButton {
var corners: CGFloat = 10
override var bounds: CGRect {
didSet {
setCorners()
setupShadow()
}
}
private func setupShadow() {
self.layer.masksToBounds = true
self.layer.cornerRadius = 6.0
self.dropShadow(color: UIColor.gray, opacity: 0.4, offSet: CGSize(width: 1, height: 1), radius: 6, scale: true)
}
private func setCorners(){
self.layer.cornerRadius = self.corners
self.layer.masksToBounds = true
}
}
@IBAction func loginPressed(_ sender: AnyObject) {
/*view.endEditing(true)
if(txtMail.text == "" || txtPassword.text == ""){
return
}
settings.setValue("normal", forKey: "loginType")
settings.setValue(txtMail.text, forKey: "email")
settings.setValue(txtPassword.text, forKey: "password")
makeLogin()*/
AlertManager(title: "Test", message: "Test").show()
}For the alert I use this class:
class AlertManager{
let alert:UIAlertController
var addAceptButton: Bool = true
init(title:String, message:String) {
self.alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
}
func addAction(action:UIAlertAction) -> Void {
self.alert.addAction(action)
}
func addActionAndRemoveFirst(action:UIAlertAction) -> Void {
self.addAction(action: action)
addAceptButton = false
}
func show() -> Void {
DispatchQueue.main.async {
if self.addAceptButton{
self.alert.addAction(UIAlertAction(title: "Aceptar", style: UIAlertActionStyle.default, handler: nil))
}
let appDelegate = UIApplication.shared.delegate as! AppDelegate
var cont = appDelegate.window!.rootViewController!
while((cont.presentedViewController) != nil){
cont = cont.presentedViewController!
}
cont.present(self.alert, animated: true, completion: nil)
}
}
}Why it happens? Why the background color of the button changes after the alert present on the controller?