IOS, how to make a subview transparent view opaque?

I have a view as a subtitle of another view, then I set the alpha value of the paternal view to about 0.5, but it also makes the subview transparent even when its alpha value is set to 1. Since I can make the subview opaque (opaque) when his look at his father has alpha less than 1?

+7
ios
source share
5 answers

Closest you will get colorWithAlphaComponent: Using something like the following, you can set the alpha component of the background of the parent view, and this will not affect subviews.

 [yourSuperview setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.5]]; 
+15
source share

If you set the parent view to 0.5, the whole sub item will also be 0.5 or less. You will have to come up with a different design approach.

+1
source share

You must have two designs for the parent view. One of them will be β€œon”, showing it as it is, and the other will be a β€œdisabled” design that will contain a transparent background.

You cannot do this with alpha, as subviews inherit alpha. If a

parent.alpha = x

and

view.alpha = y,

then the actual alpha representation will be:

x * y

0
source share

I think you created View by Storyboard. I have already encountered this problem. Find the code below, this is correct in my case.

 [MyParentView setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.6]]; 

Hope this can help you.

0
source share

For Swift 4.2

  self.yoursuperview.backgroundColor = UIColor.black.withAlphaComponent(0.5) 
0
source share

All Articles