将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地址(二次) 推荐点击以 ...
随机推荐
- 【文档】一、Mysql Binlog概述
Binlog是一系列日志文件,他们包含的内容是Mysql数据内容的改变.如果想开启binlog功能,需要在启动时带上--log-bin参数. binlog是从Mysql3.23.14版本开始的.它包含 ...
- JavaScript设计模式-10.工厂模式实例xhr
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- erlang尾递归练习
1 %%计算链表长度尾递归实现 2 lez(N) -> lez(N, 0). 3 4 lez([], Acc) -> Acc; 5 lez([_ | T], Acc) -> lez( ...
- window.location和document.location的区别分析
用户不能改变document.location(因为这是当前显示文档的位置).但是,可以改变window.location (用其它文档取代当前文档)window.location本身也是一个对象,而 ...
- Android6.0内核移植(2):kernel编译内核
普通步骤是:用来编译整个Android源码 source build/envsetup.sh lunch sabresd_6dq-user make -j20 不过每次这样太繁琐,下面来单独编译ker ...
- LOJ #6022. 重组病毒
Description 支持以下操作 1.access一个点 2.问一个点上面的重链的个数 3.换根 , 并access原来的根 Solution 对于重链个数 , 我们在 \(access\) 的时 ...
- 跟着Nisy一起学习C语言
编辑器是使用环境turboc的IDE,使用dos窗口中的edit作为编辑器,有点类似于vim:使用的是xp-sp3的虚拟机上的系统. Nisy说要有两种语言,脚本语言以及一个底层语言,比如现在我的py ...
- [转]asp.net权限认证:HTTP基本认证(http basic)
本文转自:http://www.cnblogs.com/lanxiaoke/p/6353955.html HTTP基本认证示意图 HTTP基本认证,即http basic认证. 客户端向服务端发送一个 ...
- emit 方法表翻译
Name Description Add Adds two values and pushes the result onto the evaluation stack.添加两个值并将结果推送到评 ...
- linux运维人员成长
原文地址:https://blog.csdn.net/kwame211/article/details/78059331 初级篇 linux运维人员常用工具拓扑详见: 1rsync工具 很多地方经常会 ...