How can i draw a bottom curve of the uiview using uibezierpath?

南楼画角 提交于 2021-02-10 06:30:47

问题


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 point C
  • 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!