将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地址(二次) 推荐点击以 ...
随机推荐
- Spring Security OAuth 2开发者指南译
Spring Security OAuth 2开发者指南译 介绍 这是用户指南的支持OAuth 2.0.对于OAuth 1.0,一切都是不同的,所以看到它的用户指南. 本用户指南分为两部分,第一部分为 ...
- res/raw与assets目录的区别
1.相同点: 两者都会原封不动的保存在apk包中,不会被编译成二进制码. 2.不同点: raw目录下只能存放文件,不能存放下一级的文件夹,而assets可以存放下一级的文件夹. raw目录下的资源会映 ...
- 理解Python语言里的异常(Exception)
Exception is as a sort of structured "super go to".异常是一种结构化的"超级goto". 作为一个数十年如一日 ...
- [转]OData and Authentication – Part 6 – Custom Basic Authentication
本文转自:https://blogs.msdn.microsoft.com/astoriateam/2010/07/21/odata-and-authentication-part-6-custom- ...
- openvpn应用场景案例【转】
转载至:http://www.linuxfly.org/post/86/ 一.案例1 针对不同的客户端指定不同的等级和权限.通常的方法是:1.每个客户端分配不同的IP地址:2.利用防火墙对不同的IP地 ...
- Solr环境配置
1.准备 第一步下载JDK1.8.0_131Tomcat9.0.7 注意版本的兼容性 第二歩下载solr,目前使用的是solr-7.3.0 2.安装 1. 将 solr 压缩包解压,并将solr- ...
- 记一次tomcat自动退出问题
问题 环境: centos/tomcat8/jdk1.8 最近遇到部署在服务器的tomcat总是过一段时间就自动结束进程 ; 通过监控tomcat 日志文件(tail -f ./logs/catali ...
- github flow
github flow Github flow 是Git flow的简化版,专门配合"持续发布".它是 Github.com 使用的工作流程 它只有一个长期分支,就是master, ...
- spring底层原理解析
注解测试:如何使用注解(去掉配置文件)开发 新建MainConfig类 注解测试:新建MainTest2注解测试,用来测试//AnnoatationConfigApplicationContext: ...
- FisherYates费雪耶兹随机置乱算法
public class FisherYates { public static void main(String[] args) { int[] arr = new int[10]; // 初始有序 ...