Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS how to make subview of a transparent view opaque?

Tags:

ios

I have a view as the subview of another view, then I set the alpha value of the father view something like 0.5, but this also makes the subview transparent even when its alpha value is set to 1. So how can I make the subview non-transparent(opaque) when its father view has an alpha value less than 1?

like image 404
axl411 Avatar asked Sep 28 '14 02:09

axl411


2 Answers

The closest you're going to get is colorWithAlphaComponent:. Using something like the following, you can set the alpha component of the parent view's background, and it won't affect subviews.

[yourSuperview setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.5]];
like image 141
rebello95 Avatar answered Oct 17 '22 21:10

rebello95


The following method worked for me.

superView.backgroundColor = .clear

Now that alpha property of superview is not altered, it won't affect the alpha of its subview. Hence, subviews will be opaque(if you have a background color for it).

like image 38
Manikandan.Gopal Avatar answered Oct 17 '22 22:10

Manikandan.Gopal