iOS/설명
[iOS] CALayer mask
Sky Titan
2022. 7. 2. 13:28
728x90
Apple Developer Documentation
developer.apple.com
CALayer mask
- mask는 alpha channel(선택 영역)을 이용하여 layer의 content를 보여줄 영역을 지정해주는 layer이다.
- 즉, content와 background를 얼마만큼 보여줄건지를 정해준다.
- mask layer 지정 시 size와 position을 지정해주어야 정확하게 Masking이 된다.
- mask를 지정하는 layer는 superlayer가 없어야한다.
- UIView에도 mask라는 속성이 있다.
Example
let center: CGPoint = CGPoint(x: redView.bounds.width / 2, y: redView.bounds.height / 2)
let radius: CGFloat = redView.bounds.width / 2
let mask = CAShapeLayer()
mask.path = UIBezierPath(arcCenter: center, radius: radius, startAngle: 0, endAngle: .pi * 2, clockwise: false).cgPath
redView.layer.mask = mask
- 원형 모양 마스크 적용
mask 적용 전:

mask 적용 후:

728x90