2015-01-20 2 views
1

여기 내 UIView의 둥근 모서리 스타일을 사용하려면, 그리고 내 코드입니다 :UIView의 TopLeft 및 TopRight 모서리를 둥근 모서리로 변경하는 방법은 무엇입니까?

UIBezierPath *maskPath1 = [UIBezierPath bezierPathWithRoundedRect:self.styleView1.bounds 
               byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight 
                cornerRadii:CGSizeMake(4, 4)]; 
CAShapeLayer *maskLayer1 = [[CAShapeLayer alloc] init]; 
maskLayer1.frame = self.styleView1.bounds; 
maskLayer1.path = maskPath1.CGPath; 
self.styleView1.layer.borderWidth = 1; 
[self.styleView1.layer setBorderColor:[[UIColor lightGrayColor] CGColor]]; 
self.styleView1.layer.mask = maskLayer1; 

효과는 같다 : enter image description here

포토샵 깃털 효과처럼 코너에 비어 있습니다 . enter image description here

어떻게 일어날 수 있도록 :

는하지만 내가 원하는 것은이 무엇입니까?

+0

그냥 'TopLeft'와'TopRight'를 모서리를 둥글게해서이 두 스레드가 제 질문에 어울리지 않을 수 있도록 설정하고 싶습니다. –

+0

@Don_Chen 시도 (http://stackoverflow.com/questions/25616382/how-to-set-cornerradius-for-only-bottom-left-bottom-right-and-top-left-corner-of) 및 (http://stackoverflow.com/questions/10167266/how-to-set-cornerradius-for-only-top-left-and-top-right-corner-of-a-uiview) –

답변

1

당신은 참조 코드 검사 (how to set cornerRadius for only bottom-left,bottom-right and top-left corner of a UIView?) 아래와 같이 평면도에 대한 반경을 설정할 수 있습니다.

UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:yourView.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight) cornerRadii:CGSizeMake(10.0, 10.0)]; 

CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init]; 
shapeLayer.frame = yourView.bounds; 
shapeLayer.path = path.CGPath; 
yourView.layer.mask = shapeLayer; 

및 다음과 같이 표시됩니다. enter image description here

+0

감사합니다. 나는 [링크] (http://stackoverflow.com/questions/25616382/how-to-set-cornerradius-for-only-bottom-left-bottom-right-and-top-left-corner-of)를 따랐습니다. 댓글을 달고 마침내 답을 찾았습니다. @Justin Boo와 마찬가지로 마법은 ** CAShapeLayer와 (과) 다른 것입니다. –

4

self가 UIViewController 또는 UISplitViewController 인 경우 self에는 경계가 없으므로 컨트롤러입니다.

이 하나의 시도 :

CGRect bounds = self.view.bounds; 
UIBezierPath *maskPath; 
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.styleView1.bounds 
           byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight) 
             cornerRadii:CGSizeMake(10.0, 10.0)]; 

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; 
maskLayer.frame = bounds; 
maskLayer.path = maskPath.CGPath; 
self.styleView1.layer.mask = maskLayer; 
+0

이 답변으로 만족한다면, 제 대답을 받아주세요. 그래서 다른 개발자가 이것을 따를 것입니다. –

+0

하지만 'TopLeft'와'TopRight'를 모서리를 둥글게하고 모든 4 개의 모서리를 정하고 싶지는 않습니다. –

+0

하지만 질문은 "둥근 모서리에 UIView 스타일을 변경하는 방법"이었습니다. 상단 코너에 대한 언급이 없습니다 –

관련 문제