Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not to update the subview with superview alpha value

Tags:

ios

iphone

ios4

My question is when i added a view as subview to Root view.When i changed the alpha value of root view same is occurring in subview also.Actually i don't need the updating in subview.Is there any solution to do like that.

like image 922
SURESH SANKE Avatar asked Jun 05 '12 06:06

SURESH SANKE


4 Answers

This will change only the alpha of the root view, not the others

    self.view.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.5];
like image 124
shabbirv Avatar answered Sep 30 '22 18:09

shabbirv


Building on the answer by @shabbirv, one can also use IB's color picker

color picker

like image 42
bauerMusic Avatar answered Sep 27 '22 18:09

bauerMusic


You'd need to change the structure of your views. Instead of laying your subviews out on the roots view, create a layer ontop of your root view, but still add the subviews to the root. When changing the layer's alpha it won't effect the subviews. Example structure below.

Your current structure:

RootView->Subviews //Changing RootView alpha effects Subviews.

Needed Structure:

RootView->View->Subviews(Still Added to RootView) //Changing alpha of Layer doesn't effect subviews.

Hope this helps.

like image 32
skram Avatar answered Sep 30 '22 18:09

skram


This will also solve this by changing root view color by below way, this will not affect the subview.

[rootView setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.7]];
like image 1
Pankaj Bhardwaj Avatar answered Sep 28 '22 18:09

Pankaj Bhardwaj