IOS学习 绘图 UIBezierPath 绘基本图形、样式设置、渲染填充
来源:互联网 发布:网络摄像头哪个牌子好 编辑:程序博客网 时间:2024/05/22 01:38
#import "CZView.h"
@implementation CZView
-(void)drawRect:(CGRect)rect{
//1.为什么要重写drawRect:方法
// 只有在drawRect:才能获取上下文对象 --->才能绘图
//2.rect参数:就是指当前视图的bounds属性
//3.什么时候调用drawRect:方法
// 1.视图第一次被显示的时候系统调用
// 2.执行重绘的时候
//4.不要手动调用这个方法 (系统会自动调用) drawRect:
// 5.如果要手动调用执行重绘 [self setNeedsDisplay] / [self setNeedsDisplayInRect:<#(CGRect)#>]
[selfdemo8];
}
- (void) demo9{
// 1. 获取"图形上下文"
CGContextRef ctx =UIGraphicsGetCurrentContext();
// 2.创建矩形路径
UIBezierPath *path = [UIBezierPathbezierPathWithRect:CGRectMake(100,100, 200, 100)];
// 3.创建一个圆心路径
UIBezierPath *path1 = [UIBezierPathbezierPathWithArcCenter:CGPointMake(200,150) radius:80startAngle:0endAngle:M_PI *2 clockwise:1];
// 4.创建一个矩形路径
UIBezierPath *path2 = [UIBezierPathbezierPathWithRect:CGRectMake(250,30, 20, 200)];
// 5.把刚刚创建的路径依次添加到上下文对象中
CGContextAddPath(ctx, path2.CGPath);
CGContextAddPath(ctx, path1.CGPath);
CGContextAddPath(ctx, path.CGPath);
// 说明:被覆盖过奇数次的点填充,被覆盖过偶数次的点不填充
// 6.渲染
CGContextDrawPath(ctx,kCGPathEOFill);
}
-(void)demo8{
// 1. 获取"图形上下文"
CGContextRef ctx =UIGraphicsGetCurrentContext();
//2.以顺时针的方式画一个大圆
UIBezierPath *path = [UIBezierPathbezierPathWithArcCenter:CGPointMake(150,150) radius:100startAngle:0endAngle:M_PI *2 clockwise:YES];
// 3.以逆时针画一个小圆
UIBezierPath *path1 = [UIBezierPathbezierPathWithArcCenter:CGPointMake(150,150) radius:50startAngle:0endAngle:M_PI *2 clockwise:NO];
//4.添加路径到上下文中
CGContextAddPath(ctx, path1.CGPath);
CGContextAddPath(ctx, path.CGPath);
// 默认填充模式: nonzero winding number rule(非零绕数规则)从左到右跨过, +1。从右到左跨过, -1。最后如果为0,那么不填充,否则填充
//渲染
CGContextDrawPath(ctx,kCGPathFill);
}
//绘制弧线
-(void)demo7{
//获取上下文对象
CGContextRef ctx =UIGraphicsGetCurrentContext();
//创建路径对象
//1.圆心
CGPoint centerP =CGPointMake(150,150);
//2.半径
CGFloat radius =100;
//3.起始角度
CGFloat start =0;
//4.结束角度
CGFloat end =0.5*M_PI;//2Pi为整圆
//5.clockwise 顺时针:YES 逆时针:NO
UIBezierPath * path = [UIBezierPathbezierPathWithArcCenter:centerPradius:radius startAngle:startendAngle:end clockwise:YES];
//回到圆心,画扇形
[path addLineToPoint:centerP];
[path closePath]; //关闭路径
//将路径对象加入上下文对象中
CGContextAddPath(ctx, path.CGPath);
//渲染
CGContextStrokePath(ctx);
}
//绘制椭圆形
-(void)demo6{
//获取上下文对象
CGContextRef ctx =UIGraphicsGetCurrentContext();
//创建路径对象
UIBezierPath *path = [UIBezierPathbezierPathWithOvalInRect:CGRectMake(50,50, 200, 100)];
//将路径对象加入上下文对象中
CGContextAddPath(ctx, path.CGPath);
//渲染
// CGContextStrokePath(ctx);
CGContextFillPath(ctx);
}
//绘制圆形
-(void)demo5{
//获取上下文对象
CGContextRef ctx =UIGraphicsGetCurrentContext();
//创建路径对象
UIBezierPath *path = [UIBezierPathbezierPathWithRoundedRect:CGRectMake(50,50, 200, 200)cornerRadius:100];
//将路径对象加入上下文对象中
CGContextAddPath(ctx, path.CGPath);
//渲染
CGContextStrokePath(ctx);
}
//绘制带圆角的矩形
-(void)demo4{
//获取上下文对象
CGContextRef ctx =UIGraphicsGetCurrentContext();
//创建路径对象
UIBezierPath *path = [UIBezierPathbezierPathWithRoundedRect:CGRectMake(50,50, 200, 100)cornerRadius:30];
//将路径对象加入上下文对象中
CGContextAddPath(ctx, path.CGPath);
//渲染
CGContextFillPath(ctx);
}
//绘制正方形(简单写法)
-(void)demo3{
//获取上下文对象
CGContextRef ctx =UIGraphicsGetCurrentContext();
//创建路径添加到上下文中
CGContextAddRect(ctx,CGRectMake(50,50, 100, 100));
//设置绘图样式
//1 设置线的stroke颜色
[[UIColorredColor] setStroke];
//设置填充颜色
// [[UIColor greenColor] setFill];
//设置颜色
// [[UIColor blueColor] set];
//2.1.2 设置线宽
CGContextSetLineWidth(ctx,10);
//2.1.3 设置线头样式
CGContextSetLineCap(ctx,kCGLineCapRound);
//2.1.4 设置线的连接处样式
// CGContextSetLineJoin(ctx, kCGLineJoinRound);
//渲染
CGContextStrokePath(ctx);
// CGContextFillPath(ctx);
}
//绘制四边形
-(void)demo2{
//获取上下文对象
CGContextRef ctx =UIGraphicsGetCurrentContext();
//创建路径对象
UIBezierPath *path = [UIBezierPathbezierPathWithRect:CGRectMake(50,50, 200, 100)];
//将路径对象加入上下文对象中
CGContextAddPath(ctx, path.CGPath);//将path转化成CGPath
//炫染
//1.边线样式
// CGContextDrawPath(ctx, kCGPathStroke);
// CGContextStrokePath(ctx);
//2.填充样式
// CGContextDrawPath(ctx, kCGPathFill);
CGContextFillPath(ctx);
}
//绘制线段
-(void)demo1{
//获取上下文对象
CGContextRef ctx =UIGraphicsGetCurrentContext();
//创建路径,添加到上下文对象中
//1.确定起点
CGContextMoveToPoint(ctx,50, 50);
//2.添加一条线
CGContextAddLineToPoint(ctx,200, 200);
//3.再添加一条线
CGContextAddLineToPoint(ctx,50, 200);
//4.闭合的线
CGContextAddLineToPoint(ctx,50, 50);
// CGContextClosePath(ctx);
//另画一条线
CGContextMoveToPoint(ctx,100, 50);
CGContextAddLineToPoint(ctx,250, 50);
//炫染
CGContextStrokePath(ctx);
}
@end
- IOS学习 绘图 UIBezierPath 绘基本图形、样式设置、渲染填充
- iOS-UIBezierPath绘制基本图形
- iOS基本图形绘制--UIBezierPath
- IOS学习 绘图 UIBezierPath 绘饼状图
- iOS绘图CALayer、UIBezierPath运用(边框、填充、复制、渐变)
- 【iOS学习】三、利用UIBezierPath绘图
- iOS UIBezierPath图形绘制
- iOS CAShapeLayer和UIBezierPath绘图
- iOS图形绘制UIBezierPath篇
- iOS 使用UIBezierPath 绘制图形
- Quartz2D绘图<四>图形填充
- iOS绘图-UIBezierPath的使用
- UIBezierPath绘图
- 绘图 UIBezierPath
- 【IOS 开发学习总结-OC-67】Quartz 2D绘图(4-4)——图形变换+填充处理+core image 滤镜
- ios学习整理(二)使用drawRect:方法自定义绘图和UIBezierPath类
- iOS 使用UIBezierPath与CABasicAnimation绘制图形
- iOS图形编辑之UIBezierPath小结
- poj 3608(旋转卡壳求解两凸包之间的最短距离)
- 字典树
- hdoj1025Constructing Roads In JGShining's Kingdom【LIS】
- 我的第一个嵌入式linux驱动(基于韦东山led驱动)
- [linux]查看端口号占用情况
- IOS学习 绘图 UIBezierPath 绘基本图形、样式设置、渲染填充
- 运算器的特殊实现方法
- hdoj1078FatMouse and Cheess【记忆化搜索】
- 深度优先搜索DFS
- Hamx安装失败的问题
- C++虚函数
- Qt 16进制字符串跟QByteArray互转
- java数据类型划分
- 1042 - Secret Origins