博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用CAShapeLayer绘制小人
阅读量:6862 次
发布时间:2019-06-26

本文共 1969 字,大约阅读时间需要 6 分钟。

上一篇讲解了CAShapeLayer的知识点和绘制圆角矩形,在这里实现一个小人的绘制,代码如下:

 UIView*bgv=[[UIView alloc]initWithFrame:self.view.bounds];

    bgv.backgroundColor=[UIColor lightGrayColor];

    [self.view addSubview:bgv];

      

    //绘制小人

     UIBezierPath*path=[[UIBezierPath alloc]init];

    [path addArcWithCenter:CGPointMake(200, 200) radius:50 startAngle:0 endAngle:2*M_PI clockwise:YES];

    [path moveToPoint:CGPointMake(100, 300)];

    [path addLineToPoint:CGPointMake(300, 300)];

    [path moveToPoint:CGPointMake(200, 250)];

    [path addLineToPoint:CGPointMake(200, 350)];

    [path addLineToPoint:CGPointMake(150, 400)];

    [path moveToPoint:CGPointMake(200, 350)];

    [path addLineToPoint:CGPointMake(250, 400)];

 

 

   CAShapeLayer*shapeLayer=[CAShapeLayer layer];

    shapeLayer.strokeColor=[UIColor redColor].CGColor;

    shapeLayer.fillColor=[UIColor clearColor].CGColor;

    shapeLayer.lineWidth=5;

    shapeLayer.path=path.CGPath;

    shapeLayer.lineJoin=kCALineJoinRound;

    shapeLayer.lineCap=kCALineCapRound;

    [bgv.layer addSublayer:shapeLayer];

 

最后介绍一下 使用CATextLayer绘制文本:

 CATextLayer*textLayer=[CATextLayer layer];

    textLayer.frame=CGRectMake(10, 400, self.view.bounds.size.width-20, self.view.bounds.size.height-400);

    [bgv.layer addSublayer:textLayer];

    

    textLayer.foregroundColor=[UIColor blackColor].CGColor;

    textLayer.alignmentMode=kCAAlignmentJustified;

    textLayer.wrapped=YES;

    

     NSString *text = @"Lorem ipsum dolor sit amet, consectetur adipiscing \ elit. Quisque massa arcu, eleifend vel varius in, facilisis pulvinar \ leo. Nunc quis nunc at mauris pharetra condimentum ut ac neque. Nunc elementum, libero ut porttitor dictum, diam odio congue lacus, vel \ fringilla sapien diam at purus. Etiam suscipit pretium nunc sit amet \ lobortis";

    textLayer.string=text;

    

    UIFont *font=[UIFont systemFontOfSize:15];

    CFStringRef fontName=(__bridge CFStringRef)(font.fontName);

    CGFontRef fontRef=CGFontCreateWithFontName(fontName);

    textLayer.font=fontRef;

    textLayer.fontSize=font.pointSize;

    CGFontRelease(fontRef);

 效果如下:

转载于:https://www.cnblogs.com/envyhappy/p/5029946.html

你可能感兴趣的文章
随机生成验证码信息
查看>>
[codevs1036]商务旅行<LCA:tarjan&倍增>
查看>>
socket
查看>>
Linux指令
查看>>
技术人员的发展之路
查看>>
简单易懂,原码,补码,反码
查看>>
maven项目打包额外lib目录
查看>>
关于经纬度的开发日志
查看>>
JQuery合并table单元格--有限制(table格式需要注意)
查看>>
Moqui学习之代码分析mantle priceServices.xml
查看>>
[转]Browserify —— 利用Node.js实现JS模块化加载
查看>>
wxPython:进度条Gauge介绍
查看>>
js解析器的执行原理
查看>>
sass部分知识小结
查看>>
LCS 模板+规定长度的上升子序列个数(数值不同为不同)
查看>>
lua表排序
查看>>
[git]本地分支关联远程分支
查看>>
SQL Server:属性ErrorLogFile 不可用于JobServer“[SERVER]......”的问题时的解决方案
查看>>
浅解多线程(二)
查看>>
div+css
查看>>