IOS UIBezierPath使用方法详解
2015-09-20 23:41
966 查看
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 initWi
4000
thFrame:frame];
if (self) {
self.backgroundColor = [UIColor whiteColor];
}
return self;
}
@end
它的一个重要方法
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 initWi
4000
thFrame:frame];
if (self) {
self.backgroundColor = [UIColor whiteColor];
}
return self;
}
@end
相关文章推荐
- RequireJS学习笔记(转)
- ARC环境下,自动释放UIViewController...
- 【WPF学习】WPF、WinForm(C#)多线程编程并更新界面(UI)/子线程更新主界面方式
- ios学习笔记——UIScrollView
- Android UI界面shape的用法
- 扩展easyui 的表单验证
- NGUI 源码分析- AnchorPoint
- hdoj2670Girl Love Value【01背包】
- 八位 UUID
- uinty3d导入错误问题解决
- iOS 【UIKit-按钮移动操作】
- Longest Consecutive Sequence——Leetcode
- leetcode - N-Queens
- 最小生成树 POJ 3625Building Roads解题报告
- iOS程序-UIScrollView的基本使用
- String、StringBuffer与StringBuilder之间区别
- 【遍历枚举】hdu 5288 OO’s Sequence
- 利用UIEdgeInsets属性修改UIButton的图片,文字位置
- NGUI 源码分析- UIWidgetInspector
- 接口测试工具SoapUI Pro5.1.2基本使用20150920