CoreGraphics画线
来源:互联网 发布:淘宝挖宝酱 假货 编辑:程序博客网 时间:2024/05/21 15:38
首先你是要继承自UIView的,然后重写drawRcet:(CGRect)rect
先说下面这几个,可以找我要Demo,直接留言即可。
1.画线
- (void)drawRect:(CGRect)rect
{
// Drawing code
//都以CG开头
CGContextRef context =UIGraphicsGetCurrentContext();//创建一块画板,现在这个方法创建的是GetCurrentContext,就是这个View的frame,也即全屏
//下面的绘制全都依托与这个context
CGContextMoveToPoint(context,40, 40);//把画笔移动到一个点,第一个参数就是画板,后两个参数一次为x和y的坐标
CGContextAddLineToPoint(context,80, 80);//向某个点画一条线,第一个参数就是画板,后两个参数一次为x和y的坐标
CGContextSetLineWidth(context,10);//綫有多粗
CGContextSetStrokeColorWithColor(context, [UIColoryellowColor].CGColor);//线的颜色,第二个参数是CGColor,需要转一下
CGContextDrawPath(context,kCGPathStroke);//画,第二个参数是都描绘什么,可选择只画线,或者只填充,或者都画
}
2.画框
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGContextRef context =UIGraphicsGetCurrentContext();
CGContextAddRect(context,CGRectMake(40,40, 40, 40));//画框,第二个参数是一个rect
CGContextSetLineWidth(context,2);
CGContextSetStrokeColorWithColor(context, [UIColorgreenColor].CGColor);
CGContextSetFillColorWithColor(context, [UIColorredColor].CGColor);//设置填充颜色
CGContextDrawPath(context,kCGPathFillStroke);
}
3.画圆
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGContextRef context =UIGraphicsGetCurrentContext();//创建一块画板,现在这个方法创建的是GetCurrentContext,就是这个View的frame,也即全屏
//下面的绘制全都依托与这个context
CGContextSetLineWidth(context,1);//綫有多粗
CGContextSetStrokeColorWithColor(context, [UIColoryellowColor].CGColor);//线的颜色,第二个参数是CGColor,需要转一下
CGContextSetFillColorWithColor(context, [UIColorredColor].CGColor);//设置填充颜色
CGContextAddEllipseInRect(context,CGRectMake(40,40, 40, 80));//圆是画在这个框里填充的
CGContextDrawPath(context,kCGPathFillStroke);//画,第二个参数是都描绘什么,可选择只画线,或者只填充,或者都画
}
4.画弧
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGContextRef context =UIGraphicsGetCurrentContext();//创建一块画板,现在这个方法创建的是GetCurrentContext,就是这个View的frame,也即全屏
//下面的绘制全都依托与这个context
CGContextSetLineWidth(context,1);//綫有多粗
CGContextSetStrokeColorWithColor(context, [UIColoryellowColor].CGColor);//线的颜色,第二个参数是CGColor,需要转一下
CGContextAddArc(context,90, 90, 50,0, M_PI/3,0);//第二个参数和第三个参数是弧的圆心,第四个参数radius是半径,第五个参数startAngle是起点角度,第六个参数endAngle是终点的角度,最后一个参数是方向只有0或者1
CGContextSetFillColorWithColor(context, [UIColorredColor].CGColor);//设置填充颜色
CGContextDrawPath(context,kCGPathFill);//画,第二个参数是都描绘什么,可选择只画线,或者只填充,或者都画
}
5.随意画
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGContextRef context =UIGraphicsGetCurrentContext();//创建一块画板,现在这个方法创建的是GetCurrentContext,就是这个View的frame,也即全屏
//下面的绘制全都依托与这个context
CGContextSetLineWidth(context,1);//綫有多粗
CGContextMoveToPoint(context,90, 90);//起点
CGContextAddLineToPoint(context,90, 190);
CGContextAddLineToPoint(context,190, 190);
CGContextClosePath(context);//闭合
CGContextSetStrokeColorWithColor(context, [UIColoryellowColor].CGColor);//线的颜色,第二个参数是CGColor,需要转一下
CGContextSetFillColorWithColor(context, [UIColorredColor].CGColor);//设置填充颜色
CGContextDrawPath(context,kCGPathStroke);//画,第二个参数是都描绘什么,可选择只画线,或者只填充,或者都画
}
- CoreGraphics画线
- CoreGraphics
- CoreGraphics
- CoreGraphics
- CoreGraphics
- iOS开发的2D绘制--CoreGraphics的简单使用一(画线条)
- 画线
- 画线
- 画线
- 画线
- 画线
- 画线
- 画线
- CoreGraphics入门
- CoreGraphics画图
- CoreGraphics.framework
- CoreGraphics画图
- CoreGraphics--CGPoint
- 编程小练习(3)
- Eclipse开发android问题 - admob广告
- 关于unity中 使用Protorbuf-net 序列化对象(iphone)
- Tinyxml-2源码学习
- NFC支持所有类型的卡的读取
- CoreGraphics画线
- IDL structures array
- C++标准转换运算符const_cast
- DICOM医学图像处理:Orthanc Plugin SDK实现WADO服务
- java代码设计原则
- SVM推荐阅读文献及博客
- c#初体验
- dhcpd.conf 详解
- 杭电DP题库及解题思路