10

For example:

  1. I set UIView's alpha property as alpha = 0, Does that means its opaque property be treated as opaque=YES?

  2. How opaquealpha and backgroundColor affect the performance?

  3. Anything else?...

Similar Questions

2 Answers 2

24

backgroundColor is the color that appears in the back of a UIView. By default, it's nil, resulting in a clear background color for the UIView. To assign a background to your UIView, assign a UIColor like so:

myView.backgroundColor = [UIColor greenColor];

You can also set the backgroundColor to be an image:

myView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed@"myImage"]];

alpha is the opacity of the view. You can use this attribute to fade a UIView and make it partially transparent. The value can range from 0 (completely invisible) to 1 (completely opaque).


opaque is a boolean value that indicates whether the UIView is opaque or not. If you've set the alpha to anything less than 1, then you should set opaque to NO:

myView.opaque = NO;

Apple's documentation explains why and how the opaque property works:

This property provides a hint to the drawing system as to how it should treat the view. If set to YES, the drawing system treats the view as fully opaque, which allows the drawing system to optimize some drawing operations and improve performance. If set to NO, the drawing system composites the view normally with other content. The default value of this property is YES.

An opaque view is expected to fill its bounds with entirely opaque content—that is, the content should have an alpha value of 1.0. If the view is opaque and either does not fill its bounds or contains wholly or partially transparent content, the results are unpredictable. You should always set the value of this property to NO if the view is fully or partially transparent.

1
  • nice reply. it helps me a lot.
    – demon
    May 21, 2013 at 3:54
6

opaque meaning:

not transparent

transparency meaning:

see throughness,not opaque

alpha meaning:

The inventors of RGBA model named alpha after the Greek letter in the classic linear interpolation formula αA + (1-α)B

To understand we can assume alpha is synonym for opaque in this graphic and image context.

Relation between opaque,transparency and alpha:

opaque is directly propotional to alpha and inversely propotional to transparency i.e increase in alpha value results in increase in opaque and and decrease transparency

if alpha is 1.0 for a view then it's completely opaque

if alpha is 0.0 for a view then it's completely transparent..

relation between opaque,alpha and backgroundcolor:

he alpha will also affect the alpha of the backround color i.e. if the background color is 0.5 transparent and the alpha is also 0.5, this has the effect of making the background view's alpha 0.25 (0.5 * 0.5)

Opaque perfomance:

if u set opaque as YES then there is a increase in performance because blending is not gonna take place with underlying view or color

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.