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

#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. TStringList 常用操作

    //TStringList 常用方法与属性: var   List: TStringList;   i: Integer; begin   List := TStringList.Create;   ...

  2. Android自动截屏小脚本

    @echo off echo * 截图文件将保存在 E:\pic下,以当前日期+时间命名. echo ================================================= ...

  3. Open CV 图像显示(1)

      演示:读入一张图片,并显示   #include "stdafx.h"   #include <opencv2/core/core.hpp>   #include  ...

  4. HIT2739 The Chinese Postman Problem(最小费用最大流)

    题目大概说给一张有向图,要从0点出发返回0点且每条边至少都要走过一次,求走的最短路程. 经典的CPP问题,解法就是加边构造出欧拉回路,一个有向图存在欧拉回路的充分必要条件是基图连通且所有点入度等于出度 ...

  5. 每天一个Linux命令---tcpdump

    用简单的话来定义tcpdump,就是:dump the traffic on a network,根据使用者的定义对网络上的数据包进行截获的包分析工具. tcpdump可以将网络中传送的数据包的“头” ...

  6. ural 1147. Shaping Regions

    1147. Shaping Regions Time limit: 0.5 secondMemory limit: 64 MB N opaque rectangles (1 ≤ N ≤ 1000) o ...

  7. 【原】iOS学习39网络之数据请求

    1. HTTP和HTTPS协议 1> URL URL全称是Uniform Resource Locator(统一资源定位符)通过1个URL,能找到互联网上唯一的1个资源 URL就是资源的地址.位 ...

  8. BZOJ4624 : 农场种植

    设$A[i][j]=[a[i][j]=G],B[i][j]=[b[i][j]=L]$,枚举右下角,则对应$(A-B)^2$的和就是匹配成功的格子数. $(a-b)^2=a^2+b^2-2ab$,将矩阵 ...

  9. XCOJ 1168 (搜索+期望+高斯消元法)

    题目链接: http://xcacm.hfut.edu.cn/oj/problem.php?id=1168 题目大意:D是起点,E是终点.每次等概率往某个方向走,问到达终点的期望步数.到不了终点或步数 ...

  10. 20145304 Java第八周学习报告

    20145304<Java程序设计>第八周学习总结 教材学习内容总结 NIO NIO使用频道来衔接数据节点,在处理数据时,NIO可以让你设定缓冲区容量,在缓冲区中对感兴趣的数据区块进行标记 ...