2016-06-23 6 views
0

내 이미지의 두 하단 모서리 만 둥글게하고 싶습니다. Objective-C에서 많은 예제를 발견했으며 Swift에서는 거의 아무 것도 발견하지 못했습니다. Swift로 이미지의 일부 모서리를 둥글게 만드는 방법

내가 뭘 발견하지만, 그것은 나에게 오류를 제공합니다

let rectShape = CAShapeLayer() 

     rectShape.bounds = self.image.frame 
     rectShape.position = self.image.center 
     rectShape.path = UIBezierPath(roundedRect: self.image.bounds,  byRoundingCorners: .BottomLeft | .BottomRight, cornerRadii: CGSize(width: 20, height: 20)).CGPath 

     self.image.layer.backgroundColor = UIColor.greenColor().CGColor 

     self.image.layer.mask = rectShape 

내가 오류가 rectShape.path와 일치하고 신속한에서

No '|' candidates produce the expected contextual result type 'UIRectCorner' 

답변

3

이 방식을 변경 있음을 알려줍니다 우리 이런 것들을 넣어. 객관적인 C에서 그것은 | 내가 테스트

let rectShape = CAShapeLayer() 

    rectShape.bounds = self.image.frame 
    rectShape.position = self.image.center 
    rectShape.path = UIBezierPath(roundedRect: self.image.bounds,  byRoundingCorners: [.BottomLeft, .BottomRight], cornerRadii: CGSize(width: 20, height: 20)).CGPath 

    self.image.layer.backgroundColor = UIColor.greenColor().CGColor 

    self.image.layer.mask = rectShape 
+0

감사하며 노력하고 있습니다 : 별도 옵션,하지만 빠른 당신은 배열처럼 넣어 가지고! 빠른 답변 주셔서 감사합니다! –

+0

이것은 완벽하게 작동했습니다! – user7097242

+0

이 코드를'viewDidLayoutSubviews()'에 추가했는지 확인하십시오. viewDidLoad에서이 코드를 사용해 보았는데 문제가 있습니다. – user7097242

0
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: [.TopLeft, .BottomLeft], cornerRadii: CGSize(width: 3, height: 3)) 
+0

이렇게해도 효과가 있지만 설명 텍스트를 추가하여 다른 사람들이 내 대답을 이해할 수 있도록하는 이유를 설명하십시오. – AlBlue

관련 문제