iOS 贝塞尔曲线简单使用

UIBezierPath只能写在UIView drawRect:方法中使用才有效,否则不会出现效果

绘制一个矩形:

            UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(20, 100 50, 50) cornerRadius:5];
            [[UIColor blueColor] set];
            [path fill];

fill换成stroke是空心的

绘制一个自定义图形,例如三角形:

 UIBezierPath *path = [UIBezierPath bezierPath];
 [path moveToPoint:CGPointMake(node.coordinate.x-NODEWH/2, node.coordinate.y-NODEWH/2)];
 [path addLineToPoint:CGPointMake(node.coordinate.x-NODEWH/2, node.coordinate.y+NODEWH/2)];
 [path addLineToPoint:CGPointMake(node.coordinate.x+NODEWH/2, node.coordinate.y)];
 [path addLineToPoint:CGPointMake(node.coordinate.x-NODEWH/2, node.coordinate.y-NODEWH/2)];
 [[UIColor blueColor] set];
 [path fill];

坐标闭合即可,调用view的setNeedsDisplay方法会调用drawRect:(CGRect)rect方法重新绘制

你可能感兴趣的:(Objective-C)