问题
I'm tried to draw a bottom curve on UIimageview using uibezierpath. I don't know how to do that?
- (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;
}
i already tried like this https://imgur.com/a/WKykdyU
I expect the output of https://imgur.com/a/BqETMlc
回答1:
This should help you get going...
With a UIBezierPath
:
- move to point
A
- add quad curve to point
B
with control pointC
- add line to point
D
- add line to point
E
- close the path
Here's a simple UIView
subclass:
@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
That produces the above image for a 200-pt tall view.
来源:https://stackoverflow.com/questions/57788503/how-can-i-draw-a-bottom-curve-of-the-uiview-using-uibezierpath