***************基本图像绘制 画线

#import "HMLineView.h"

@implementation HMLineView

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
} // Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation. /**
* 什么调用:当你视图第一次显示的时候就会调用
* 作用:绘图
* @param rect = self.bounds
*/
- (void)drawRect:(CGRect)rect
{
// 1.获取上下文
CGContextRef ctx = UIGraphicsGetCurrentContext(); // 2.拼接路径
UIBezierPath *path = [UIBezierPath bezierPath]; CGPoint startP = CGPointMake(, );
CGPoint endP = CGPointMake(, );
CGPoint controlP = CGPointMake(, );
[path moveToPoint:startP];
[path addQuadCurveToPoint:endP controlPoint:controlP]; // 3.把路径添加到上下文
CGContextAddPath(ctx, path.CGPath); // 4.渲染上下文到视图
CGContextStrokePath(ctx); } - (void)draw2Line
{
// 1.获取上下文
CGContextRef ctx = UIGraphicsGetCurrentContext(); // 2.拼接路径
UIBezierPath *path = [UIBezierPath bezierPath]; // 设置起点
[path moveToPoint:CGPointMake(, )]; // 添加一条线到某个点
[path addLineToPoint:CGPointMake(, )]; // // 设置起点
// [path moveToPoint:CGPointMake(10, 10)];
//
// // 添加一条线到某个点
// [path addLineToPoint:CGPointMake(125, 100)]; UIBezierPath *path1 = [UIBezierPath bezierPath]; [path1 moveToPoint:CGPointMake(, )]; [path1 addLineToPoint:CGPointMake(, )]; // 3.把路径添加到上下文
CGContextAddPath(ctx, path.CGPath);
CGContextAddPath(ctx, path1.CGPath); // 设置绘图状态
// 设置线宽
CGContextSetLineWidth(ctx, );
CGContextSetLineCap(ctx, kCGLineCapRound);
// CGContextSetRGBStrokeColor(ctx, 1, 0, 0, 1);
[[UIColor redColor] set]; // 4.渲染上下文到视图
CGContextStrokePath(ctx);
} - (void)drawLine
{
// 1.获取上下文
// CGContextRef CG CoreGraphics Ref 引用
// 目前学的上下文都跟UIGraphics有关,以后想直接获取上下文,直接敲一个UIGraphics
CGContextRef ctx = UIGraphicsGetCurrentContext(); // 2.设置绘图信息(拼接路径)
UIBezierPath *path = [UIBezierPath bezierPath]; // 设置起点
[path moveToPoint:CGPointMake(, )]; // 添加一条线到某个点
[path addLineToPoint:CGPointMake(, )];
[path addLineToPoint:CGPointMake(, )];
// 3.把路径添加到上下文
// 直接把UIKit的路径转换成CoreGraphics,CG开头就能转
CGContextAddPath(ctx, path.CGPath); // 4.把上下文渲染到视图
// Stroke描边
CGContextStrokePath(ctx);
} @end

******基本的图形的绘制

#import "HMShapeView.h"

@interface HMShapeView()

@property (nonatomic, weak) UILabel *label;

@end

@implementation HMShapeView

- (UILabel *)label
{
if (_label == nil) {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
label.text = @"s";
label.font = [UIFont systemFontOfSize:];
label.textColor = [UIColor yellowColor];
label.textAlignment = NSTextAlignmentCenter;
[self addSubview:label];
_label = label;
}
return _label;
} - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
} - (void)awakeFromNib
{
// self.label;
} // Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation. // 扇形行
- (void)drawRect:(CGRect)rect
{
// Drawing code // 1.获取上下文
CGContextRef ctx = UIGraphicsGetCurrentContext(); // 2.拼接路径
CGPoint center = CGPointMake(, );
CGFloat radius = ;
CGFloat startA = ;
CGFloat endA = M_PI_2;
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES]; [path addLineToPoint:center]; // 3.把路径添加到上下文
CGContextAddPath(ctx, path.CGPath); // 4.渲染上下文
// CGContextStrokePath(ctx);
CGContextFillPath(ctx); } - (void)drawArc
{
// 1.获取上下文
CGContextRef ctx = UIGraphicsGetCurrentContext(); // 2.拼接路径
CGPoint center = CGPointMake(, );
CGFloat radius = ;
CGFloat startA = ;
CGFloat endA = M_PI_2;
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES]; // 3.把路径添加到上下文
CGContextAddPath(ctx, path.CGPath); // 4.渲染上下文
CGContextStrokePath(ctx);
} // 圆行
- (void)drawCircle
{
// 1.获取上下文
CGContextRef ctx = UIGraphicsGetCurrentContext(); // 2.拼接路径
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(, , , )]; // 3.把路径添加到上下文
CGContextAddPath(ctx, path.CGPath); // 4.渲染上下文
CGContextStrokePath(ctx); }
// 矩形
- (void)drawRectangle
{
// 1.获取上下文
CGContextRef ctx = UIGraphicsGetCurrentContext(); // 2.拼接路径
UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(, , , )];
path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(, , , ) cornerRadius:]; // 3.把路径添加到上下文
CGContextAddPath(ctx, path.CGPath); // 4.渲染上下文
CGContextStrokePath(ctx);
} //三角
- (void)drawSupernene
{
// 1.获取上下文
CGContextRef ctx = UIGraphicsGetCurrentContext(); // 2.拼接路径
UIBezierPath *path = [UIBezierPath bezierPath]; CGPoint startP = CGPointMake(, ); [path moveToPoint:startP]; [path addLineToPoint:CGPointMake(, )]; [path addLineToPoint:CGPointMake(, )]; // 从路径的终点连接到起点
[path closePath];
// [path addLineToPoint:startP]; // 3.把路径添加到上下文
CGContextAddPath(ctx, path.CGPath); [[UIColor blueColor] setFill];
[[UIColor redColor] setStroke]; CGContextSetLineWidth(ctx, ); // 4.渲染上下文
// CGContextStrokePath(ctx);
// CGContextFillPath(ctx);
// 即填充又描边 kCGPathFillStroke
CGContextDrawPath(ctx, kCGPathFillStroke);
} @end

IOS第16天(1,Quartz2D基本图像绘制)的更多相关文章

  1. IOS第16天(5,Quartz2D雪花)

    *** #import "HMView.h" @interface HMView() { int count; } @property (nonatomic, assign) CG ...

  2. IOS第16天(4,Quartz2D柱状图)

    *** #import "HMBarView.h" #import "UIColor+Random.h" @implementation HMBarView - ...

  3. IOS第16天(3,Quartz2D饼图)

    **** #import "HMPieView.h" #import "UIColor+Random.h" @implementation HMPieView ...

  4. IOS第16天(2,Quartz2D下载进度条)

    *************自定义下载的view的方法 #import "HMProgressView.h" @interface HMProgressView() @propert ...

  5. iOS:quartz2D绘图(处理图像,绘制图像并添加水印)

    绘制图像既可以重写drawRect:方法并在该方法中绘制,也可以不用重写该方法,它有封装好的函数获取自己的图像绘制上下文,即UIGraphicsBeginImageContext(CGSize siz ...

  6. iOS开发UI之Quartz2D使用(绘制基本图形)

    iOS开发UI篇—Quartz2D使用(绘制基本图形) 一.简单说明 图形上下文(Graphics Context):是一个CGContextRef类型的数据 图形上下文的作用:保存绘图信息.绘图状态 ...

  7. iOS开发UI篇—Quartz2D使用(绘制基本图形)

    iOS开发UI篇—Quartz2D使用(绘制基本图形) 一.简单说明 图形上下文(Graphics Context):是一个CGContextRef类型的数据 图形上下文的作用:保存绘图信息.绘图状态 ...

  8. Python的工具包[2] -> matplotlib图像绘制 -> matplotlib 库及使用总结

    matplotlib图像绘制 / matplotlib image description  目录 关于matplotlib matplotlib库 补充内容 Figure和AxesSubplot的生 ...

  9. HTML5 canvas图像绘制方法与像素操作属性和方法

    图像绘制方法 drawImage()        向画布上绘制图像.画布或视频 像素操作属性和方法 width                                返回 ImageData ...

随机推荐

  1. Uva 725 Division

    0.不要傻傻的用递归去构造出一个五位数来,直接for循环最小到最大就好,可以稍微剪枝一丢丢,因为最小的数是01234 从1234开始,因为倍数n最小为2 而分子是一个最多五位数,所以分母应该小于五万. ...

  2. Scau 10327 Biggest Square

    时间限制:1000MS  内存限制:65535K提交次数:0 通过次数:0 题型: 编程题   语言: G++;GCC Description You are given a M*M cloth wi ...

  3. 静态成员函数(面向对象的static关键字)

    静态成员函数 与静态数据成员一样,我们也可以创建一个静态成员函数,它为类的全部服务而不是某一个类的具体对象服务.静态成员函数与静态数据成员一样,都是类的内部实现,属于类定义的一部分.普通的成员函数一般 ...

  4. [bzoj3813]奇数园

    仿佛现在已经完成了做题之前先开个坑的习惯,也许是为了逼迫自己去刷一些神题吧...然并卵,该剩的好多坑还是剩着呢. [bzoj3813]一道线段树好题.已经把数论忘光光了. 欧几里德算法 扩展欧几里德算 ...

  5. (转)hadoop 集群间数据迁移

    hadoop集群之间有时候需要将数据进行迁移,如将一些保存的过期文档放置在一个小集群中进行保存. 使用的是社区提供的功能,distcp.用法非常简单: hadoop distcp hdfs://nn1 ...

  6. js函数中参数的传递

    数据类型 在 javascript 中数据类型可以分为两类: 基本类型值 primitive type,比如Undefined,Null,Boolean,Number,String. 引用类型值,也就 ...

  7. Boom.TV完成350万美元融资,目标直指VR电竞直播

    3D在线电竞直播平台Boom.tv刚刚宣布已经完成350万美元的融资,该平台旨在让观众在任何设备以任意视角观看电竞比赛,并将支持VR版本. 这家位于美国加州红木城的初创公司成立于2015年,由Gupt ...

  8. 纯CSS 实现tooltip 内容提示信息效果

    Tooltip 也就是内容的提示信息,合理使用可以给用户比较好的体验. 实现方法有很多种,有很多JS 插件,我这里介绍的是纯CSS实现的方法,兼容性也比较靠谱,IE8+均可正常显示.实现方法也非常简单 ...

  9. leetcode Container With Most Water

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai).  ...

  10. JS中toFixed()方法的问题及解决方案

    最近发现JS当中toFixed()方法存在一些问题,采用原生的Number对象的原型对象上的toFixed()方法时,规则并不是所谓的“四舍五入”或者是“四舍六入五成双”,所谓“四舍六入五成双”,在百 ...