2012-03-20 12 views
0

設置角落我知道我可以做的UIView與圓角作爲在查看

view.layer.cornerRadius = 10; 

現在我想知道我怎樣才能使所選擇的角落圓角?就像在左上角和右上角,而不是在左下角和右下角。我怎麼能做到這些?

在此先感謝...

+0

即使不完全重複,我通過這些帖子找到了答案。非常感謝您的調查結果 – rakeshNS 2012-03-20 17:12:37

+0

Dupe關閉投票/鏈接是雙重目的 - 它們可以防止重複,但它們也可以幫助提問者(以及任何使用您使用的術語進行搜索的人)找到他們可能沒有的答案在提出問題之前遇到。 – jrturton 2012-03-20 17:34:34

回答

0

像這樣的事情會借鑑,只有頂部邊角 -

- (void)drawRect:(CGRect)rect 
{ 
[super drawRect:rect]; 

UIBezierPath* roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(44.5, 12.5, 69, 46) byRoundingCorners: UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii: CGSizeMake(10, 10)]; 
[[UIColor whiteColor] setFill]; 
[roundedRectanglePath fill]; 

[[UIColor blackColor] setStroke]; 
roundedRectanglePath.lineWidth = 0.5; 
[roundedRectanglePath stroke]; 

}

0

兩種方法:

1. use CALayer mask, mask out the corner you don't want. 

2. use Core Graphic, create a clip path.