IOS基础之绘图函数的使用
生活随笔
收集整理的這篇文章主要介紹了
IOS基础之绘图函数的使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
IOS基礎之繪圖函數的使用
// // HMView.m // 25-繪圖步驟 // // Created by 魯軍 on 2021/2/14. //#import "HMView.h"@implementation HMView- (void)drawRect:(CGRect)rect {[self test11];//NSLog(@"%@",NSStringFromCGRect(rect));//{{0, 0}, {300, 300}} 打印的是當前view的bounds//[self setNeedsDisplayInRect:rect]; } -(void)test11{//C hua yuanCGContextRef ctx = UIGraphicsGetCurrentContext();CGContextAddArc(ctx, 150, 150, 100, 0, 2*M_PI, 1);CGContextStrokePath(ctx); }-(void)test10{//使用純畫圓函數 繪制圓形//ArcCenter 圓心//radius 半徑//startAngle 起始位置//endAngle 結束位置//clockwise 是否是順時針 1 逆時針。0。順時針UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150) radius:100 startAngle:0 endAngle:2*M_PI - M_PI_2 clockwise:YES];[path stroke]; } -(void)test9{//C 畫橢圓CGContextRef ctx=UIGraphicsGetCurrentContext();CGContextAddEllipseInRect(ctx, CGRectMake(10, 10, 150, 100));CGContextStrokePath(ctx); } -(void)test8{//畫橢圓// UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 200, 100)];// [path stroke];//畫圓UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 200, 200)];[path stroke]; }-(void)test7{//帶圓角的矩形的繪畫//UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(100, 100, 100, 100) cornerRadius:10];//[path stroke];//畫圓UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(100, 100, 100, 100) cornerRadius:50];[path stroke]; } -(void)test6{//繪制矩形UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(100, 100, 100, 100)];[path stroke];}-(void)test5{// chun OC fang shiUIBezierPath *path = [UIBezierPath bezierPath];[path moveToPoint:CGPointMake(50, 50)];[path addLineToPoint:CGPointMake(100, 100)];[path stroke]; } -(void)test4{//c + ocCGContextRef ctx = UIGraphicsGetCurrentContext();//拼接路徑(c)CGMutablePathRef path = CGPathCreateMutable();CGPathMoveToPoint(path, NULL, 50, 50);CGPathAddLineToPoint(path, NULL, 100, 100);//拼接路徑(oc)UIBezierPath *path1 = [UIBezierPath bezierPathWithCGPath:path];[path1 addLineToPoint:CGPointMake(150, 50)];//3.路徑添加當前的上下文CGContextAddPath(ctx, path1.CGPath);//4渲染CGContextStrokePath(ctx); } -(void)test3{//oc + c// 1 獲取 當前上下文CGContextRef ctx = UIGraphicsGetCurrentContext();//拼接路徑UIBezierPath *path = [[UIBezierPath alloc] init];[path moveToPoint:CGPointMake(50, 50)];[path addLineToPoint:CGPointMake(100, 250)];//3.路徑添加當前的上下文CGContextAddPath(ctx, path.CGPath);CGContextStrokePath(ctx); } -(void)test2{//C的// 1 獲取 當前上下文CGContextRef ctx = UIGraphicsGetCurrentContext();//2 拼接路徑。CGMutablePathRef path = CGPathCreateMutable();CGPathMoveToPoint(path, NULL, 50, 50);CGPathAddLineToPoint(path, NULL, 100, 200);//3.路徑添加當前的上下文CGContextAddPath(ctx, path);//4渲染CGContextStrokePath(ctx); } -(void)test1{// 1 獲取 當前上下文CGContextRef ctx = UIGraphicsGetCurrentContext();//2 拼接路徑。 同時把路徑添加當前的上下文CGContextMoveToPoint(ctx, 50, 50); //起點CGContextAddLineToPoint(ctx, 100, 100); //終點CGContextAddLineToPoint(ctx, 150, 50); //終點CGContextMoveToPoint(ctx, 50, 200); //起點CGContextAddLineToPoint(ctx, 200, 200); //終點//3。渲染CGContextStrokePath(ctx); } @end總結
以上是生活随笔為你收集整理的IOS基础之绘图函数的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: QQ框架的搭建
- 下一篇: IOS开发基础之使用AFNetworki