码迷,mamicode.com
首页 > 移动开发 > 详细

iOS中画矩形的几种方法总结

时间:2014-08-23 17:41:21      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:style   color   os   io   strong   ar   line   new   sp   

方法1:

#pragma mark 画矩形方法1
void drawRect1(){
    
    // 1取得图形上下文
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    // 2画一条线段
    // 设置一个起点
    CGContextMoveToPoint(ctx, 20, 20);
    CGContextAddLineToPoint(ctx, 100, 100);
    
    // 3设置线宽
    CGContextSetLineWidth(ctx, 10);
    
    // 4渲染
    CGContextStrokePath(ctx);
}

方法2:
#pragma mark 画矩形方法2
void drawRect2(){
    
    // 1取得图形上下文
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    // 2画矩形,先添加到上下文
    CGContextAddRect(ctx, CGRectMake(10, 10, 50, 50));
    
    // 3渲染
    CGContextStrokePath(ctx);
}

方法3:
#pragma mark 画矩形方法3
void drawRect3(){
    // 通过UIKit的oc方法画矩形,会自动取得图形上下文
    UIRectFill(CGRectMake(10, 10, 100, 100));
}

方法4:
#pragma mark 画矩形方法4
void drawRect4(){
    
    // 1取得图形上下文
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    CGContextStrokeRect(ctx, CGRectMake(100, 100, 100, 100));
}

iOS中画矩形的几种方法总结

标签:style   color   os   io   strong   ar   line   new   sp   

原文地址:http://www.cnblogs.com/xiaokanfengyu/p/3931467.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!