글 작성자: 이지원🌩️
button.layer.shadowColor = UIColor.black.cgColor
button.layer.shadowOffset = CGSize(width: 0.0, height: 1.0)
button.layer.shadowRadius = 1.0
button.layer.shadowOpacity = 0.5

기존 플로팅 버튼은 위와 같이 그림자를 적용했는데, 디버깅을 해보니까 다음과 같은 경고가 떴다.

The layer is using dynamic shadows which are expensive to render. If possible try setting 'shadowPath', or pre-rendering the shadow into an image and putting it under the layer.

 

렌더링 비용이 많이 드니까 shadowPath를 변경하라는 경고여서, 해결책을 찾아보았다. UIBezierPath를 사용하면 된다. 다음과 같은 코드 한 줄 추가하면 해결.

button.layer.shadowPath = UIBezierPath(roundedRect: button.bounds, cornerRadius: button.layer.cornerRadius).cgPath
반응형