Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alpha vs Opacity #30

Closed
Taehyeon-Kim opened this issue Jul 11, 2022 · 0 comments
Closed

Alpha vs Opacity #30

Taehyeon-Kim opened this issue Jul 11, 2022 · 0 comments
Assignees

Comments

@Taehyeon-Kim
Copy link
Owner

Taehyeon-Kim commented Jul 11, 2022

Alpha

UIView의 인스턴스 속성

var alpha: CGFloat { get set }

이 속성의 값은 0.0 ~ 1.0까지의 부동 소수점 숫자로 이루어져있다. 0.0으로 가까워질수록 투명해지고, 1.0으로 가까워질수록 불투명해진다. 이 속성의 값을 변경하면 현재 뷰의 알파 값만 업데이트 된다. 그러나 해당 알파 값에 부여된 투명도는 하위 뷰를 포함하여 뷰의 모든 컨텐츠에 영향을 준다.

알파값에 대한 변경 사항은 애니메이션 할 수 있다.

Opacity

CALayer의 인스턴스 속성

var opacity: Float { get set }

이 속성의 값은 0.0(투명)에서 1.0(불투명) 사이여야 한다. 해당 범위를 벗어난 값은 최소값, 최대값으로 고정된다. 기본 값은 1.0이다. Alpha 속성과는 다르게 현재 뷰만 투명도가 조정된다.

정리

  • alpha : 하위 뷰를 포함해서 모든 뷰의 투명도 조정 / UIView와 관련
  • opacity: 값이 적용된 뷰만 투명도 조정 / CALayer와 관련

위가 가장 바깥에 있는 뷰의 alpha값을 0.5로 조정한, 아래가 opacity를 50%(0.5)로 조정한 모습이다. 해당 차이를 잘 인지하고 뷰의 속성을 조정할 필요가 있다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant