How can I have an opaque UIView as a subview of a semi-transparent UIView?

前端 未结 5 1510
时光说笑
时光说笑 2020-12-24 06:47

I have a UIView with an alpha of 0.5 which I add as a subview to my primary view in order to gray-out everything else. I want to add an additional UIView to this gray UIVie

5条回答
  •  臣服心动
    2020-12-24 07:12

    Set the UIView background color alpha not it's alpha directly.

    Objective-C

    UIView *view;
    ...
    view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.6];
    

    It's not the same as:

    view.backgroundColor = [UIColor blackColor];    
    view.alpha = .6;
    

    Swift

    view.backgroundColor = UIColor.black.withAlphaComponent(0.6)
    

提交回复
热议问题