How do you create a semi-transparent background for a UIView?

前端 未结 8 1037
耶瑟儿~
耶瑟儿~ 2021-02-13 10:19

I am creating a UIView containing some text that partially covers a UIImageView. I want the user to be able to read the text and still maintain a perspective on the image undern

相关标签:
8条回答
  • 2021-02-13 10:59

    Swift 3+

    white half transparent:

    view.backgroundColor = UIColor(white: 1, alpha: 0.5)
    

    or black half transparent:

            view.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5)
    
    0 讨论(0)
  • 2021-02-13 11:09

    I think what you mean is you want the backgroundColor of your UIView to be semi transparent? If you want white/transparent use this:

    myView.backgroundColor = [UIColor colorWithWhite:myWhiteFloat alpha:myAlphaFloat];
    

    else if you want it to be another color use the general UIColor method: +colorWithRed:green:blue:alpha:

    0 讨论(0)
提交回复
热议问题