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!
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With