本文介绍基本图形的绘制:
-
三角形
-
矩形
-
圆形
-
椭圆
-
圆弧
-
封闭圆弧
2.1 绘制代码
- (void)drawRect:(CGRect)rect {
//1.获取上下文
CGContextRef ctx=UIGraphicsGetCurrentContext();
//2.拼接路径
UIBezierPath *path=[UIBezierPath bezierPath];
CGPoint startP=CGPointMake(10, 10);
[path moveToPoint:startP];
[path addLineToPoint:CGPointMake(125, 125)];
[path addLineToPoint:CGPointMake(240, 10)];
[path closePath];
//[path addLineToPoint:startP];
//3.把路径添加到上下文
CGContextAddPath(ctx, path.CGPath);
[[UIColor blueColor]setFill];
[[UIColor redColor]setStroke];
CGContextSetLineWidth(ctx, 15);
//4.渲染上下文
//CGContextStrokePath(ctx);
//CGContextFillPath(ctx);
CGContextDrawPath(ctx,kCGPathFillStroke);
}
2.2 给三角形添加文字
- (UILabel *)label{
if (_label==nil) {
UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 250, 100)];
label.text=@“s”;
label.textColor=[UIColor yellowColor];
label.font=[UIFont systemFontOfSize:60];
label.textAlignment=NSTextAlignmentCenter;
[self addSubview:label];
}
return _label;
}
- (void)awakeFromNib
{
self.label;
}
2.3 效果图
3.1 代码
- (void)drawRect:(CGRect)rect {
//1.获取上下文
CGContextRef ctx=UIGraphicsGetCurrentContext();
//2.拼接路径
UIBezierPath *paht=[UIBezierPath bezierPathWithRect:CGRectMake(10, 10, 200, 200)];
//3.把路径添加到上下文
CGContextAddPath(ctx, paht.CGPath);
//4.渲染上下文
CGContextStrokePath(ctx);
}
3.2 效果图
4.1 代码1
- (void)drawRect:(CGRect)rect {
//1.获取上下文
CGContextRef ctx=UIGraphicsGetCurrentContext();
//2.拼接路径
UIBezierPath *path=[UIBezierPath bezierPathWithOvalInRect:CGRectMake(10, 10, 200, 200)];
//3.把路径添加到上下文
CGContextAddPath(ctx, path.CGPath);
//4.渲染上下文
CGContextStrokePath(ctx);
}
4.2 代码2
- (void)drawRect:(CGRect)rect {
//1.获取上下文
CGContextRef ctx=UIGraphicsGetCurrentContext();
//2.拼接路径
UIBezierPath *paht=[UIBezierPath bezierPathWithRect:CGRectMake(10, 10, 200, 200)];
paht=[UIBezierPath bezierPathWithRoundedRect:CGRectMake(10, 10, 200, 200) cornerRadius:100];
//3.把路径添加到上下文
CGContextAddPath(ctx, paht.CGPath);
//4.渲染上下文
CGContextStrokePath(ctx);
}
4.3 效果图
5.1 代码
- (void)drawRect:(CGRect)rect {
//1.获取上下文
CGContextRef ctx=UIGraphicsGetCurrentContext();
总结
找工作是个很辛苦的事情,而且一般周期都比较长,有时候既看个人技术,也看运气。第一次找工作,最后的结果虽然不尽如人意,不过收获远比offer大。接下来就是针对自己的不足,好好努力了。
最后为了节约大家的时间,我把我学习所用的资料和面试遇到的问题和答案都整理成了PDF文档
喜欢文章的话请关注、点赞、转发 谢谢!
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门,即可获取!
工作是个很辛苦的事情,而且一般周期都比较长,有时候既看个人技术,也看运气。第一次找工作,最后的结果虽然不尽如人意,不过收获远比offer大。接下来就是针对自己的不足,好好努力了。
最后为了节约大家的时间,我把我学习所用的资料和面试遇到的问题和答案都整理成了PDF文档
喜欢文章的话请关注、点赞、转发 谢谢!
[外链图片转存中…(img-YtOOmZy9-1715838911782)]
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门,即可获取!