Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to give background color to superview only with alpha less than 1.0

    • 0
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 406
    Comment on it

    Hi,

    In many cases we have to give a background color to a superview with alpha less than 1.0. If we give color from XIB/storyboard to a superview with alpha 0.4 then it assigns the alpha 0.4 to its subviews also.

    What if we need to give alpha 0.4 only to the superview. There is a simple code for it.

    Assign the color to the superview as below:

        [self.blueView setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.4]];
    

    This way the alpha 0.4 will be given only to the superview and not to the sub views.

    Check screenshot below:

    Here is the alpha 0.4 given from storyboard to superview. The alpha will be given to subviews as well.

    Check screenshot below:

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: