Quartz2D-基本图形绘制
2016-07-27 22:22
288 查看
Quartz2D简单实用
//
// GRedView.m
// Quartz2D-基本图形绘制
//
// Created by gaocai on 16/7/27.
// Copyright © 2016年 gaocai. All rights reserved.
//
#import "GRedView.h"
@implementation GRedView
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
CGPoint center = CGPointMake(rect.size.width * 0.5, rect.size.height * 0.5);
CGFloat radius = rect.size.width * 0.5 - 10;
CGFloat start = 0;
CGFloat end = M_PI;
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:start endAngle:end clockwise:YES];
//内部自动调用上下文
// [path stroke];
[path fill];
}
- (void)drawRect {
//1.获取上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
//2.获取描述路径
UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(100, 100, 100, 100)];
//3.吧路径添加到上下文
CGContextAddPath(ctx, path.CGPath);
//4.将上下文的内容显示到View上
CGContextFillPath(ctx);
}
/**
* 画曲线
*/
- (void)drawQuadCurve {
//1获取上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
//2获取描述路径
UIBezierPath *path = [UIBezierPath bezierPath];
//设置起点
[path moveToPoint:CGPointMake(20, 100)];
//添加另一点还有一个控制点
[path addQuadCurveToPoint:CGPointMake(200, 200) controlPoint:CGPointMake(100, 10)];
//3把路径添加到上下文
CGContextAddPath(ctx, path.CGPath);
//把上下文的内容显示到View上
CGContextStrokePath(ctx);
}
/**
* 画线
*/
- (void)drawLine{
//1首先取得上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
//2其次获得一个描述路径
UIBezierPath *path = [UIBezierPath bezierPath];
//设置线的起点
[path moveToPoint:CGPointMake(10, 100)];
//链接线的第二个点
[path addLineToPoint:CGPointMake(200, 20)];
//当添加第三个点时会把第二个点当成起始点
[path addLineToPoint:CGPointMake(100, 200)];
//同上
[path addLineToPoint:CGPointMake(10, 100)];
//设置线的宽度
CGContextSetLineWidth(ctx, 10);
//设置顶点的角为圆角
CGContextSetLineJoin(ctx, kCGLineJoinRound);
//设置起始点为圆角
CGContextSetLineCap(ctx, kCGLineCapRound);
//空心时的线颜色
[[UIColor yellowColor] setStroke];
// [[UIColor yellowColor] setFill];//实心时线颜色 和CGContextFillPath对应
//3然后将描绘的路径添加到上下文中
CGContextAddPath(ctx, path.CGPath);
//4最后渲染到View上
CGContextStrokePath(ctx);//空心
// CGContextFillPath(ctx);//实心
}
@end
//
// GRedView.m
// Quartz2D-基本图形绘制
//
// Created by gaocai on 16/7/27.
// Copyright © 2016年 gaocai. All rights reserved.
//
#import "GRedView.h"
@implementation GRedView
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
CGPoint center = CGPointMake(rect.size.width * 0.5, rect.size.height * 0.5);
CGFloat radius = rect.size.width * 0.5 - 10;
CGFloat start = 0;
CGFloat end = M_PI;
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:start endAngle:end clockwise:YES];
//内部自动调用上下文
// [path stroke];
[path fill];
}
- (void)drawRect {
//1.获取上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
//2.获取描述路径
UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(100, 100, 100, 100)];
//3.吧路径添加到上下文
CGContextAddPath(ctx, path.CGPath);
//4.将上下文的内容显示到View上
CGContextFillPath(ctx);
}
/**
* 画曲线
*/
- (void)drawQuadCurve {
//1获取上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
//2获取描述路径
UIBezierPath *path = [UIBezierPath bezierPath];
//设置起点
[path moveToPoint:CGPointMake(20, 100)];
//添加另一点还有一个控制点
[path addQuadCurveToPoint:CGPointMake(200, 200) controlPoint:CGPointMake(100, 10)];
//3把路径添加到上下文
CGContextAddPath(ctx, path.CGPath);
//把上下文的内容显示到View上
CGContextStrokePath(ctx);
}
/**
* 画线
*/
- (void)drawLine{
//1首先取得上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
//2其次获得一个描述路径
UIBezierPath *path = [UIBezierPath bezierPath];
//设置线的起点
[path moveToPoint:CGPointMake(10, 100)];
//链接线的第二个点
[path addLineToPoint:CGPointMake(200, 20)];
//当添加第三个点时会把第二个点当成起始点
[path addLineToPoint:CGPointMake(100, 200)];
//同上
[path addLineToPoint:CGPointMake(10, 100)];
//设置线的宽度
CGContextSetLineWidth(ctx, 10);
//设置顶点的角为圆角
CGContextSetLineJoin(ctx, kCGLineJoinRound);
//设置起始点为圆角
CGContextSetLineCap(ctx, kCGLineCapRound);
//空心时的线颜色
[[UIColor yellowColor] setStroke];
// [[UIColor yellowColor] setFill];//实心时线颜色 和CGContextFillPath对应
//3然后将描绘的路径添加到上下文中
CGContextAddPath(ctx, path.CGPath);
//4最后渲染到View上
CGContextStrokePath(ctx);//空心
// CGContextFillPath(ctx);//实心
}
@end
相关文章推荐
- RxJava 之 Hello World
- Linux为CentOS 7配置静态IP地址
- [CF Gym 100827E] Hill Number [2014-2015 ACM-ICPC Pacific Northwest Regional Contest E]
- A Point Light Demo
- java基础--06对象内存图
- POJ1154
- Mac终端基本指令,一些实用命令的收集.
- 20160727笔记
- Iframe+js 异步上传
- HDU4027:Can you answer these queries?(线段树 单点更新 区间求和)
- unique函数的使用
- hdu 1068 Girls and Boys(最大独立集模板)
- Python写xml文件
- 微信授权验证
- 机器学习笔记:Fisher Vector基本原理与用法
- mysql在linux上出现Access denied for user 'root'@'localhost' (using password: NO)解决方案
- LintCode:O(1)时间检测2的幂次
- 自适应Canny边缘检测
- 安装Qt-vs-addin插件时 出现的进度条不动 或不小心中止情况
- Struts2小结