[英]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.