IOS UIBezierPath使用方法详解

UIBezier类可以绘制不同类型的图形,它是Core Graphics框架的封装,可以绘制不同的图形,线,多边形,矩形,圆,椭圆,弧形,二次元贝塞尔曲线,三次贝塞尔曲线dengdeng 

它的一个重要方法

1、-(void)stroked   //空心的线的图形

2、-(void)fill   //实心的图形

它的使用方法:

1、创建一个UIBezierPath对象

2、使用方法moveToPoint:去设置起始坐标

3、添加活着Curve去定义一个或者多个subpaths

4、通过调用UIBezier的属性改变形状


代码如下 简陋代码

//
//  BezierView.m
//  BezierPathDemo
//
//  Created by xiaoqiang on 15/9/20.
//  Copyright © 2015年 xiaoqiang. All rights reserved.
//

#import "BezierView.h"

@implementation BezierView

//重写
-(void)drawRect:(CGRect)rect{
    
    UIColor *color = [UIColor redColor];
    [color set];//设置颜色

    UIBezierPath *path = [[UIBezierPath alloc] init];
    
    [path setLineWidth: 5];//设置比的宽度
    [path  setLineCapStyle:kCGLineCapRound];
    [path setLineJoinStyle:kCGLineJoinRound];
    
    //线
    [path moveToPoint:CGPointMake(150, 50)];
    [path addLineToPoint:CGPointMake(100, 100)];
    [path addLineToPoint:CGPointMake(100, 200)];
    [path addLineToPoint:CGPointMake(200, 200)];
    [path addLineToPoint:CGPointMake(200, 100)];
    [path closePath];//不加这句 它不会自动首尾链接
    [path stroke];
    
    //创建一个矩形
    UIBezierPath *path1 = [UIBezierPath bezierPathWithRect:CGRectMake(50, 220, 50, 100)];
    path1.lineWidth = 5;
    path1.lineCapStyle = kCGLineCapRound;
    path1.lineCapStyle = kCGLineJoinRound;
    [path1 stroke];
    
    //创建一个圆
    UIBezierPath *path2 = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(200, 220, 100, 100)];
    [path2 stroke];
    
    //椭圆
    UIBezierPath *path3 = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(50, 350, 100, 50)];
    [path3 stroke];
    
    //弧形
    UIBezierPath *path4 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(200, 350) radius:50 startAngle:0 endAngle:M_PI * 2 clockwise:YES];
    [path4 stroke];
    
    //二次贝塞尔曲线
    UIBezierPath *path5 =[UIBezierPath bezierPath];
    [path5 moveToPoint:CGPointMake(200, 450)];
    [path5 addQuadCurveToPoint:CGPointMake(100, 550) controlPoint:CGPointMake(300, 550)];
    [path5 stroke];
    
    //三次贝塞尔曲线
    UIBezierPath *path6 =[UIBezierPath bezierPath];
    [path6 moveToPoint:CGPointMake(200, 550)];
    [path6 addCurveToPoint:CGPointMake(300, 600) controlPoint1:CGPointMake(500, 700) controlPoint2:CGPointMake(100, 750)];
    [path6 stroke];
    
    
}

-(id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

@end




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值