iOS中画矩形的几种方法总结
方法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));
}
轉載于:https://www.cnblogs.com/xiaokanfengyu/p/3931467.html
總結
以上是生活随笔為你收集整理的iOS中画矩形的几种方法总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 13-11-27新的一天
- 下一篇: HDU 3951 (博弈) Coin G