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 yuan
CGContextRef 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 shi
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(50, 50)];
[path addLineToPoint:CGPointMake(100, 100)];
[path stroke];
}
-(void)test4{
//c + oc
CGContextRef 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/260081.html
標籤:其他
下一篇:[8] ADB 查看日志
