我想圓我UIView
使用類似值
top-left-radius:20;
bottom-right-radius:5;
bottom-left-radius:5;
和top-right-radius:10;
IOS:可以圓有不同的價值半徑在每個角落
//For rounder `UIRectCornerBottomLeft & UIRectCornerBottomRight` I use
UIBezierPath *maskPath0 = [UIBezierPath bezierPathWithRoundedRect:self.messageView.bounds byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(5.0, 5.0)];
CAShapeLayer *maskLayer0 = [[CAShapeLayer alloc] init];
maskLayer0.frame = self.bounds;
maskLayer0.path = maskPath0.CGPath;
self.messageView.layer.mask = maskLayer0;
//For rounder `TopRight` I use
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.messageView.bounds byRoundingCorners:(UIRectCornerTopRight) cornerRadii:CGSizeMake(10.0, 10.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.messageView.layer.mask = maskLayer;
//For rounder `TopLeft` I use
UIBezierPath *maskPath2 = [UIBezierPath bezierPathWithRoundedRect:self.messageView.bounds byRoundingCorners:(UIRectCornerTopLeft) cornerRadii:CGSizeMake(20.0, 20.0)];
CAShapeLayer *maskLayer2 = [[CAShapeLayer alloc] init];
maskLayer2.frame = self.bounds;
maskLayer2.path = maskPath2.CGPath;
self.messageView.layer.mask = maskLayer2;
但結果我得到的是與視圖拐角半徑爲TopLeft
,值爲20. 我該如何實現這個圓角?任何幫助將非常感激。
您需要使用相同的對象添加所有的拐角半徑,截至目前最後一個對象正在應用拐角半徑。 –
@VatsalK你是對的,但現在我不知道把它添加到同一個對象中,你能用代碼來描述它嗎?非常感謝你 –
在這種情況下,你需要按照你的要求繪製形狀,你可以參考這個[link](http://stackoverflow.com/questions/8702696/drawing-smooth-curves-methods-needed)或者您可以製作相同形狀的圖像並將圖像設置爲背景。 –