Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are the options in my UIAlertController dim and how can I fix it?

This is a weird one. I'm making a UIAlertController with the following code:

let optionMenu = UIAlertController(title: nil, message: "Choose Option", preferredStyle: UIAlertControllerStyle.ActionSheet)

    let action = UIAlertAction(title: "Action 1", style: .Default, handler: {
        (alert: UIAlertAction!) -> Void in
        print("Cancelled")
    })

    let action2 = UIAlertAction(title: "Action 2", style: .Default, handler: {
        (alert: UIAlertAction!) -> Void in
        print("Cancelled")
    })

    let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: {
        (alert: UIAlertAction!) -> Void in
        print("Cancelled")
    })

    optionMenu.addAction(cancelAction)
    optionMenu.addAction(action)
    optionMenu.addAction(action2)

    self.presentViewController(optionMenu, animated: true, completion: nil)

And here's what it looks like on screen. The options are dim (I believe pulling in or being affected by the rear views).

Dimmed Options

I was able to add this code to make it pure white, but the nice-ness of the separation goes away.

let subview = optionMenu.view.subviews.first! as UIView
let alertContentView = subview.subviews.first! as UIView
alertContentView.backgroundColor = UIColor.whiteColor()
alertContentView.layer.cornerRadius = 2    

And it looks like this: Non-dimmed, but not quite right

Any ideas on how to not let the background affect the options in the UIAlertController?

I added this UIAlertController to a page with a white background and it looked like it should.

Thanks!

like image 416
Taylor Smith Avatar asked Nov 09 '22 03:11

Taylor Smith


1 Answers

It's not a bug. Nothing is "dimmed". The alert buttons are translucent, so they are darker over a dark background. They are also reddish over a red background and bluish over a blue background; that's what translucent means. All action sheets in all apps look like this. There's no problem here. Don't worry, be happy.

like image 132
matt Avatar answered Nov 14 '22 21:11

matt