Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the opacity and alpha the same thing for UIView [duplicate]

Tags:

I want to use animation to change UIView's color to make it fade, however, somehow i can't access and set opacity, but i can set alpha. I wonder if alpha and opacity are the same? Search on the web and I didnt find a good answer. Thanks a lot for your help!

like image 775
trillions Avatar asked Mar 13 '13 09:03

trillions


People also ask

What is Alpha in VFX?

The alpha channel is a color component that represents the degree of transparency (or opacity) of a color (i.e., the red, green and blue channels). It is used to determine how a pixel is rendered when blended with another.

What is opacity 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.

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.


2 Answers

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.

like image 71
alex Avatar answered Sep 20 '22 13:09

alex


Just try by yourself!

CALayer has opacity from 0 to 1, while UIView has alpha from 0 to 1. They have the same visual effect.

like image 29
Cyrille Avatar answered Sep 19 '22 13:09

Cyrille