Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the relationship among opaque, alpha, and backgroundColor of a UIView?

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

  • UIView performance: opaque, backgroundColor, clearsContextBeforeDrawing?
  • Is UIView's opaque property with a value of YES in conflict with its backgroundColor property with a value of [UIColor clearColor]?
  • Cocoa/iPhone: BackgroundColor and Opaque Properties
like image 719
Emily Avatar asked Jan 12 '12 03:01

Emily


People also ask

Is opacity and alpha same?

Actually "opacity" means "value of alpha-channel" of your UIView . When a view is fully opaque this means its alpha = 1 , when a view is fully transparent (non-opaque) its alpha = 0 . As about properties of CALayer and UIView in Cocoa, yes, they provide the same functionality.

What is opaque view in Swift?

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.

How to set opacity of color in swift?

Any SwiftUI view can be partially or wholly transparent using the opacity() modifier. This accepts a value between 0 (completely invisible) and 1 (fully opaque), just like the alpha property of UIView in UIKit.

How do you do opacity in Swift?

Basic Swift Code for iOS AppsView's Alpha value is a floating-point number in the range 0.0 to 1.0, where 0.0 represents totally transparent and 1.0 represents totally opaque. Changing the value of this property updates the alpha value of the current view only.


2 Answers

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.

like image 166
bryanjclark Avatar answered Oct 19 '22 11:10

bryanjclark


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

like image 21
Durai Amuthan.H Avatar answered Oct 19 '22 12:10

Durai Amuthan.H