cornerRadius

Little_Machine_Human_·2025년 1월 10일

// 특정 모서리만 둥글게 만들기 위해 필요합니다
extension View {
    func cornerRadius(_ radius: CGFloat, corners: UIRectCorner, strokeColor: Color, lineWidth: CGFloat) -> some View {
        let shape = RoundedCorner(radius: radius, corners: corners)
        return self
            .clipShape(shape)
            .overlay(
                shape
                    .stroke(strokeColor, lineWidth: lineWidth)
            )
    }
}

struct RoundedCorner: Shape {
    var radius: CGFloat = .infinity
    var corners: UIRectCorner = .allCorners
    
    func path(in rect: CGRect) -> Path {
        let path = UIBezierPath(roundedRect: rect, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
        
        return Path(path.cgPath)
    }
    
}

위 코드는 특정뷰를 둥글게 처리하기 위함으로 만들어진 코드다.

문제가 있다.

상하좌우 사각형이 있을때 특정 부분을 지우고싶다면?
생각을 해봤는데 그냥 외곽선을 그라데이션을 준다음
.clear처리해버리면
굳이 새로운 수식이나 코드를 안짜도 될거라는 생각이 들었다.

꽤 재밌게 생각이 났던 꼼수다.

profile
while(true){ 가족(); 건강(); 자기개발(); }

0개의 댓글