将NSString变成贝塞尔曲线
将NSString变成贝塞尔曲线
https://github.com/aderussell/string-to-CGPathRef
NSString中的字符串是可以通过CoreText框架将其转换成贝塞尔曲线的.
源码:
//
// RootViewController.m
// StringPath
//
// Copyright (c) 2014年 Y.X. All rights reserved.
// #import "RootViewController.h"
#import "UIBezierPath+TextPaths.h"
#import "FontPool.h"
#import "YXGCD.h" @interface RootViewController () @property (nonatomic, strong) GCDTimer *timer; @end @implementation RootViewController - (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor]; // 注册字体
[FontPool registerFont:bundleFont(@"新蒂小丸子体.ttf")
withName:@"新蒂小丸子体"]; // 获取形状的layer
CAShapeLayer *line1 = [CAShapeLayer new];
line1.frame = CGRectMake(, , , );
line1.fillColor = [UIColor clearColor].CGColor;
line1.strokeColor = [UIColor blackColor].CGColor;
line1.strokeStart = .f;
line1.strokeEnd = .f;
line1.lineWidth = .f; // 从string上获取到CGPath
line1.path = [UIBezierPath pathFromString:@"游贤明"
WithFont:[UIFont fontWithName:CUSTOM_FONT(@"新蒂小丸子体", )
size:.f]].CGPath;
// 让文字按照正常的顺序显示
line1.bounds = CGPathGetBoundingBox(line1.path);
line1.geometryFlipped = YES; // 设置颜色渐变layer
CAGradientLayer *colorLayer = [CAGradientLayer layer];
colorLayer.frame = CGRectMake(, , , ); // 设置遮罩
colorLayer.mask = line1;
colorLayer.colors = @[(id)[UIColor redColor].CGColor,
(id)[UIColor cyanColor].CGColor];
colorLayer.position = self.view.center;
[self.view.layer addSublayer:colorLayer]; // 动画事件
_timer = [[GCDTimer alloc] initInQueue:[GCDQueue mainQueue]];
[_timer event:^{
line1.strokeEnd = arc4random()%/.f;
colorLayer.colors = @[(id)[UIColor colorWithRed:arc4random()%/.f
green:arc4random()%/.f
blue:arc4random()%/.f
alpha:].CGColor,
(id)[UIColor colorWithRed:arc4random()%/.f
green:arc4random()%/.f
blue:arc4random()%/.f
alpha:].CGColor,
(id)[UIColor colorWithRed:arc4random()%/.f
green:arc4random()%/.f
blue:arc4random()%/.f
alpha:].CGColor,
(id)[UIColor colorWithRed:arc4random()%/.f
green:arc4random()%/.f
blue:arc4random()%/.f
alpha:].CGColor,
(id)[UIColor colorWithRed:arc4random()%/.f
green:arc4random()%/.f
blue:arc4random()%/.f
alpha:].CGColor];
} timeInterval:NSEC_PER_SEC];
[_timer start];
} @end
效果:
核心代码:
附录:
将NSString变成贝塞尔曲线的更多相关文章
- IOS贝塞尔曲线圆形进度条和加载动画
做项目让做一个加载动画,一个圈圈在转中间加一个图片,网上有好多demo,这里我也自己写了一个,中间的图片可加可不加.其中主要用到贝塞尔曲线.UIBezierPath是对CGContextRef的进一步 ...
- iOS:使用贝塞尔曲线绘制图表(折线图、柱状图、饼状图)
1.介绍: UIBezierPath :画贝塞尔曲线的path类 UIBezierPath定义 : 贝赛尔曲线的每一个顶点都有两个控制点,用于控制在该顶点两侧的曲线的弧度. 曲线的定义有四个点:起始点 ...
- canvas贝塞尔曲线
贝塞尔曲线 Bézier curve(贝塞尔曲线)是应用于二维图形应用程序的数学曲线. 曲线定义:起始点.终止点.控制点.通过调整控制点,贝塞尔曲线的形状会发生变化. 1962年,法国数学家Pierr ...
- 贝塞尔曲线(UIBezierPath)属性、方法汇总
UIBezierPath主要用来绘制矢量图形,它是基于Core Graphics对CGPathRef数据类型和path绘图属性的一个封装,所以是需要图形上下文的(CGContextRef),所以一般U ...
- 深度掌握SVG路径path的贝塞尔曲线指令
一.数字.公式.函数.变量,哦,NO! 又又一次说起贝塞尔曲线(英语:Bézier curve,维基百科详尽中文释义戳这里),我最近在尝试实现复杂的矢量图形动画,发现对贝塞尔曲线的理解馒头那么厚,是完 ...
- 贝塞尔曲线(cubic bezier)
对于css3的Transitions,网上很多介绍,相信大家都比较了解,这里用最简单的方式介绍下: transition语法:transition:<transition-property> ...
- iOS开发之画图板(贝塞尔曲线)
贝塞尔曲线,听着挺牛气一词,不过下面我们在做画图板的时候就用到贝塞尔绘直线,没用到绘制曲线的功能.如果会点PS的小伙伴会对贝塞尔曲线有更直观的理解.这篇博文的重点不在于如何用使用贝塞尔曲线,而是利用贝 ...
- 用html5的canvas画布绘制贝塞尔曲线
查看效果:http://keleyi.com/keleyi/phtml/html5/7.htm 完整代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHT ...
- 二次、三次贝塞尔曲线demo(演示+获取坐标点)
二次贝塞尔曲线demo: See the Pen quadraticCurveDemo by hanyanjun (@hanyanjun) on CodePen. 我的demo地址(二次) 推荐点击以 ...
随机推荐
- 解决UnicodeDecodeError: 'ascii' code can't decode byte 0xef in position
今天在使用python的pip安装的时候出现了这个错误 UnicodeDecodeError: 'ascii' code can't decode byte 0xef in position 7: o ...
- MySQL存储引擎 InnoDB与MyISAM的区别
来源:http://www.jb51.net/article/47597.htm 基本的差别:MyISAM类型不支持事务处理等高级处理,而InnoDB类型支持.MyISAM类型的表强调的是性能,其执行 ...
- 关于chrome下的bug
最近看了大神的一篇文章,于是尝试了一下里面说的bug以及修复 1.Chrome下absolute绝对定位元素部分display属性值不渲染bug 首先还原一下bug.. ff下的下效果 点击按钮后的效 ...
- Java SE 基础知识
常量: 常量是一种标识符,它的值在运行期间恒定不变,并且常量在程序中只能被引用,而不能被重新赋值. 常量的命名规则: 1.在 Java 中,在变量声明中加入 final 关键字代表常量,加入 stat ...
- 图像RGB2YUV与YUV2RGB格式互转介绍
1 YUV格式与RGB格式说明 由于不同国家的电视信号系统支持的图像格式不同,有YUV格式成像,也有RGB格式成像,因此为了保证兼容性,需要进行RGB与YUV格式的互转. 另外YUV格式具有亮度信息和 ...
- SQL性能调优
部分转自:http://www.cnblogs.com/luckybird/archive/2012/06/11/2544753.html 及http://www.cnblogs.com/kissdo ...
- [转]Support Composite Key in ASP.NET Web API OData
本文转自:https://code.msdn.microsoft.com/Support-Composite-Key-in-d1d53161 he default EntitySetControlle ...
- csu 1365 双向链表模拟超时
1365: Play with Chain Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 21 Solved: 5[Submit][Status][W ...
- HDU 3306 Another kind of Fibonacci ---构造矩阵***
Another kind of Fibonacci Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- K:找寻数组中第n大的数组元素的三个算法
相关介绍: 给定一个数组,找出该数组中第n大的元素的值.其中,1<=n<=length.例如,给定一个数组A={2,3,6,5,7,9,8,1,4},当n=1时,返回9.解决该问题的算法 ...