[英]How can i draw a bottom curve of the uiview using uibezierpath?
我試圖使用 uibezierpath 在 UIimageview 上繪制底部曲線。 我不知道該怎么做?
- (void)setMaskTo:(UIView*)view byRoundingCorners:
(UIRectCorner)corners
{
UIBezierPath *rounded = [UIBezierPath
bezierPathWithRoundedRect:view.bounds
byRoundingCorners:corners
cornerRadii:CGSizeMake(200.0, 200.0)];
CAShapeLayer *shape = [[CAShapeLayer alloc] init];
[shape setPath:rounded.CGPath];
view.layer.mask = shape;
}
我已經嘗試過這樣https://imgur.com/a/WKykdyU
這應該可以幫助你開始......
使用UIBezierPath
:
A
點C
將四邊形曲線添加到點B
D
E
這是一個簡單的UIView
子類:
@implementation BottomCurveView
- (void)layoutSubviews {
[super layoutSubviews];
CGRect rect = self.bounds;
CGFloat y = rect.size.height - 80.0;
CGFloat curveTo = rect.size.height;
UIBezierPath *myBez = [UIBezierPath new];
[myBez moveToPoint:CGPointMake(0.0, y)];
[myBez addQuadCurveToPoint:CGPointMake(rect.size.width, y) controlPoint:CGPointMake(rect.size.width / 2.0, curveTo)];
[myBez addLineToPoint:CGPointMake(rect.size.width, 0.0)];
[myBez addLineToPoint:CGPointMake(0.0, 0.0)];
[myBez closePath];
CAShapeLayer *maskForPath = [CAShapeLayer new];
maskForPath.path = myBez.CGPath;
[self.layer setMask:maskForPath];
}
@end
這為 200 磅高的視圖生成了上面的圖像。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.