ios 贝塞尔画图
CGContextRef context = UIGraphicsGetCurrentContext();
//写文字
CGContextSetRGBFillColor(context, 1, 0, 0, 1.0);//设置填充颜色
UIFont *font = [UIFont boldSystemFontOfSize:15.0];
// NSString *str = @"圆";
// [str drawInRect:<#(CGRect)#> withAttributes:<#(NSDictionary *)#>];
//边框圆
CGContextSetRGBStrokeColor(context, 1, 1, 1, 1.0);//画笔颜色
CGContextSetLineWidth(context, 1.0);//线的宽度
CGContextAddArc(context, 50, 100, 20, 0, 2*M_PI, 0);
CGContextDrawPath(context, kCGPathStroke);//绘制路径
//填充圆
CGContextAddArc(context, 120, 100, 25, 2*M_PI, 0, 0);//添加一个圆
CGContextDrawPath(context, kCGPathFill);//绘制填充
//填充圆 有边框
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
CGContextSetLineWidth(context, 3.0);
CGContextAddArc(context, 200, 100, 30, 0, 2*M_PI, 0);
//kCGPathFill填充非零绕数规则,kCGPathEOFill表示用奇偶规则,kCGPathStroke路径,kCGPathFillStroke路径填充,kCGPathEOFillStroke表示描线,不是填充
CGContextDrawPath(context, kCGPathFillStroke);
//画线
CGPoint aPoints[2];
aPoints[0] = CGPointMake(0, 0);
aPoints[1] = CGPointMake(self.frame.size.width, self.frame.size.height);
CGContextAddLines(context, aPoints, 2);
CGContextDrawPath(context, kCGPathStroke);
//画弧
CGContextSetRGBStrokeColor(context, 1, 1, 0.5, 1.0);
CGContextMoveToPoint(context, 50, 200);
CGContextAddArcToPoint(context, 58, 180, 66, 200, 10);
CGContextStrokePath(context);
//画矩形
CGContextStrokeRect(context, CGRectMake(50, 250, 50, 50));
CGContextFillRect(context, CGRectMake(110, 250, 50, 50));
//矩形 并填充颜色
CGContextSetLineWidth(context, 2.0);
CGContextSetFillColorWithColor(context, [UIColor greenColor].CGColor);
CGContextAddRect(context, CGRectMake(200, 250, 50, 50));
CGContextDrawPath(context, kCGPathFillStroke);
//第一种填充方式
CAGradientLayer *gradient1 = [CAGradientLayer layer];
gradient1.frame = CGRectMake(50, 320, 60, 30);
gradient1.colors = [NSArray arrayWithObjects:(id)[UIColor whiteColor].CGColor,(id)[UIColor grayColor].CGColor,(id)[UIColor blackColor].CGColor,(id)[UIColor yellowColor].CGColor,(id)[UIColor blueColor].CGColor,(id)[UIColor redColor].CGColor,(id)[UIColor greenColor].CGColor,(id)[UIColor orangeColor].CGColor,(id)[UIColor brownColor].CGColor, nil];
[self.layer insertSublayer:gradient1 atIndex:0];
//第二种填充方式
CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
CGFloat colors[] =
{
1,1,1, 1.00,
1,1,0, 1.00,
1,0,1, 1.00,
0,1,1, 1.00,
0,0,1, 1.00,
1,0,0, 1.00,
0,1,0, 1.00,
0,0,0, 1.00,
};
CGGradientRef gradient = CGGradientCreateWithColorComponents(rgb, colors, nil, sizeof(colors)/(sizeof(colors[0])*4));
CGColorSpaceRelease(rgb);
CGContextSaveGState(context);
CGContextMoveToPoint(context, 150, 320);
CGContextAddLineToPoint(context, 170, 320);
CGContextAddLineToPoint(context, 170, 350);
CGContextAddLineToPoint(context, 150, 350);
CGContextClip(context);
CGContextDrawLinearGradient(context, gradient, CGPointMake(100, 320), CGPointMake(130, 350), kCGGradientDrawsAfterEndLocation);
CGContextRestoreGState(context);
ios 贝塞尔画图的更多相关文章
- iOS Quartz2D画图
对于刚接触Quartz2D的同学来说,先了解 上下文 的概念,再从最基础的画线来具体体验Quartz2D的画图步骤 介绍Quart2D :是苹果官方的二维(平面)绘图引擎,同时支持iOS和macOS系 ...
- iOS贝塞尔曲线(UIBezierPath)的基本使用方法
简介 UIBezierPath是对Core Graphics框架的一个封装,使用UIBezierPath类我们可以画出圆形(弧线)或者多边形(比如:矩形)等形状,所以在画复杂图形的时候会经常用到. 分 ...
- UIBezierPath IOS贝塞尔曲线
//记录 贝塞尔曲线使用 //根据一个矩形画曲线 + (UIBezierPath *)bezierPathWithRect:(CGRect)rect //根据矩形框的内切圆画曲线 + (UIBezi ...
- IOS贝塞尔曲线圆形进度条和加载动画
做项目让做一个加载动画,一个圈圈在转中间加一个图片,网上有好多demo,这里我也自己写了一个,中间的图片可加可不加.其中主要用到贝塞尔曲线.UIBezierPath是对CGContextRef的进一步 ...
- iOS CGContextRef画图时的常用方法
UIView的drawRect方法 CoreGraphics绘图 综述:描述系统会调用UIView的drawRect方法,所以coreGraphics的所有实现代码放在该函数内,setNeedsDis ...
- iOS CGContextRef 画图小结
CGContextRef context = UIGraphicsGetCurrentContext(); //设置上下文 //画一条线 CGContextSetStrokeColorWithColo ...
- IOS 贝塞尔曲线切割圆角
写一个UIView扩展 1. .h文件 @interface UIView (Corner) - (void)setCornerWithType:(UIRectCorner)type Radius:( ...
- iOS - 贝塞尔曲线,折线,曲线,波浪线
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZHlsYW5fbHdiXw==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- iOS开发 贝塞尔曲线
iOS开发 贝塞尔曲线UIBezierPath - 陌云 时间 2014-03-14 11:04:00 博客园-所有随笔区 原文 http://www.cnblogs.com/moyunmo/p/ ...
随机推荐
- 京东的SSO
京东的sso流程: 初始访问状态: cookies: http请求: 1.在首页点击登陆,跳转至passport.360buy.com,给予验证cookie alc(可以试试在提交登陆信息前删除该co ...
- gcc 编译
../gcc-5.2.0/configure --enable-threads=posix --disable-checking --disable-multilib --enable-languag ...
- ElasticSearch(5)-Mapping
一.Mapping概述 映射 为了能够把日期字段处理成日期,把数字字段处理成数字,把字符串字段处理成全文本(Full-text)或精确的字符串值,Elasticsearch需要知道每个字段里面都包含了 ...
- 关于c++的引用
引用的本质 引用事实上就是两个变量指向同一个地址 int x; int &y = x; cout << &x << endl; cout << &a ...
- Gentoo启动菜单设置:使用官方LiveDVD Grub主题
设置Gentoo Grub启动主题 拷贝官方LiveDVD grub主题: 下载官方DVD,找到 /boot/grub/themes/GenGrub目录,并拷贝出来. 安装GenGrub主题: 将Ge ...
- NOIP2014-普及组复赛-第二题-比例简化
题目描述 Description 在社交媒体上,经常会看到针对某一个观点同意与否的民意调查以及结果.例如,对某一观点表示支持的有1498 人,反对的有 902人,那么赞同与反对的比例可以简单的记为14 ...
- XCode debug中添加查找debug和控制台的办法
我们每一次编码完成后紧接着便是编译运行起来,看看程序运行的结果是否达到了我们的预期,此时,我们离不开控制台给我们输出必要的信息,为此, 当程序跑起来时,我们的控制台遍自己弹出来,这是不是蛮好的? 又 ...
- erlang进程与操作系统线程
erlang多进程与多线程: 在erlang开发中,我们面对的最小执行单位是进程,当然这个进程并不是系统层面上的进程,也不是线程.而是基于erlang运行时系统的一个进程.那么erlang的多进程是如 ...
- 2015 Multi-University Training Contest 9
1001 Expression 式子不好推啊.见官方题解. 式子知道就方便了.处理好组合数和阶乘. 按区间长度从小到大递推完就好. # include <iostream> # inclu ...
- javascript动画效果之透明度
在css中的filter对应老版本的ie浏览器,opacity对应的是其他浏览器 <!DOCTYPE html> <html> <head> <meta ch ...