ios 简单绘制
来源:互联网 发布:怎么开淘宝零食店 编辑:程序博客网 时间:2024/05/21 17:05
#import "DrawView.h"
#import <CoreGraphics/CoreGraphics.h>
@implementation DrawView
- (void)drawRect:(CGRect)rect {
// drawRect: 此方法不能手动调用,可以调用以下方法间接调用
// [self setNeedsDisplay];
CGContextRef context = [selfcreateCobtext];
// [self drawLineOne:context];
//
// [self drawLineTwo:context];
//
// [self drawCylye:context];
[self drawBezierPath:context];
}
//初始化画布
- (CGContextRef )createCobtext {
// CGContextRef是一个不透明的绘画环境,简单理解为一块画布
CGContextRef context =UIGraphicsGetCurrentContext();
// 设置颜色
CGContextSetStrokeColorWithColor(context, [UIColor orangeColor].CGColor);
// 设置画笔的宽度
CGContextSetLineWidth(context,5);
return context;
}
//第一种画线方式
- (void)drawLineOne:(CGContextRef)context {
// 设置起点
CGContextMoveToPoint(context,20, 20);
// 设置下一个点
CGContextAddLineToPoint(context,200, 200);
CGContextAddLineToPoint(context,200, 500);
// 绘制
CGContextStrokePath(context);
}
//第二种方式
- (void)drawLineTwo:(CGContextRef )context {
// 通过路径来画线
CGMutablePathRef path =CGPathCreateMutable();
// 设置起点
// CGAffineTransformIdentity表示见当前的view的transform设为初始值
CGPathMoveToPoint(path, &CGAffineTransformIdentity,20, 20);
// 添加另一个点
CGPathAddLineToPoint(path, &CGAffineTransformIdentity,100, 300);
// 给画布添加路径,再次路径上画线
CGContextAddPath(context, path);
// 绘制
CGContextStrokePath(context);
}
//画圆弧
- (void)drawCylye:(CGContextRef )context {
// 参数!:context
// 参数2:圆心x
// 参数3:圆心y
// 参数4:半径
// 参数5:起始角度
// 参数6:终点角度
// 参数7:0表示顺时针,1表示逆时针
CGContextAddArc(context, 100, 100, 50,0, M_PI*2,0);
// 绘制
CGContextStrokePath(context);
}
//贝塞尔曲线
- (void)drawBezierPath:(CGContextRef)context {
CGContextMoveToPoint(context,50, 50);
// 设置下一点
// 参数1:context
// 参数2:端点1x
// 参数3:端点1y
// 参数4:端点2x
// 参数5:端点3y
// 参数6:半径
CGContextAddArcToPoint(context, 100, 300, 300,100, 100);
CGContextStrokePath(context);
}
@end
- ios 简单绘制
- iOS Quartz2D绘制简单图形
- iOS 简单的使用UIBezierPath绘制
- iOS --- OpenGLES之简单的图形绘制
- iOS 简单的使用UIBezierPath绘制
- MAC IOS 用openCV 绘制简单图形
- iOS 绘制简单图形---CGContextRef篇
- iOS 绘制简单图形---UIBezierPath篇
- IOS之Quartz2D绘图1.简单几何图形绘制
- iOS上使用Quartz 2D绘制简单图形
- 绘制折线图展示数据简单介绍-iOS客户端
- iOS图像处理(1)绘制简单的几何图形
- iOS上使用Quartz 2D绘制简单图形
- opengl 绘制简单图形
- 图形简单绘制擦除
- Android 简单图形绘制
- Winform 简单绘制公章
- OpenGL绘制简单图形
- 3.2notify和notifyAll
- 在客户端使用JSONP做跨域请求
- POJ 2975 Nim题解
- GTP(GPRS Tunnelling Protocol)协议http://blog.csdn.net/stephen_yin/article/details/6951237
- Java异步回调
- ios 简单绘制
- 信必优用144部Windows Phone组超炫矩阵屏幕
- TextView跑马灯效果
- C# 读取EXCEL数据
- 【菜鸟学Java】10:Cookie技术
- python 脚本风格
- DIV居中
- iOS 调试
- mysql判断表是否存在的语句