/**
String动画书写出来 @param string 要写的字
@param view 父视图
@param ui_font 字体大小
@param color 字体颜色
*/
- (void)createAnimationLayerWithString:(NSString*)string andView:(UIView *)view andFont:(UIFont*)ui_font andStrokeColor:(UIColor*)color{
CTFontRef font =CTFontCreateWithName((CFStringRef)ui_font.fontName,
ui_font.pointSize,
NULL);
CGMutablePathRef letters = CGPathCreateMutable(); //这里设置画线的字体和大小
NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:
(__bridge id)font, kCTFontAttributeName,
nil];
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:string
attributes:attrs];
CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)attrString);
CFArrayRef runArray = CTLineGetGlyphRuns(line); for (CFIndex runIndex = ; runIndex < CFArrayGetCount(runArray); runIndex++)
{
CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex(runArray, runIndex);
CTFontRef runFont = CFDictionaryGetValue(CTRunGetAttributes(run), kCTFontAttributeName); for (CFIndex runGlyphIndex = ; runGlyphIndex < CTRunGetGlyphCount(run); runGlyphIndex++)
{
CFRange thisGlyphRange = CFRangeMake(runGlyphIndex, );
CGGlyph glyph;
CGPoint position;
CTRunGetGlyphs(run, thisGlyphRange, &glyph);
CTRunGetPositions(run, thisGlyphRange, &position); CGPathRef letter = CTFontCreatePathForGlyph(runFont, glyph, NULL);
CGAffineTransform t = CGAffineTransformMakeTranslation(position.x, position.y);
CGPathAddPath(letters, &t, letter);
CGPathRelease(letter);
}
} CAShapeLayer *pathLayer = [CAShapeLayer layer];
pathLayer.frame = CGRectMake(, , view.frame.size.width, view.frame.size.height );
pathLayer.bounds = CGPathGetBoundingBox(letters);
pathLayer.geometryFlipped = YES;
pathLayer.path = letters;
pathLayer.strokeColor = [color CGColor];
pathLayer.fillColor = nil;
pathLayer.lineWidth = 1.0f;
pathLayer.lineJoin = kCALineJoinBevel;
[view.layer addSublayer:pathLayer]; CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
pathAnimation.duration = 5.0;
pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];
[pathLayer addAnimation:pathAnimation forKey:@"strokeEnd"]; CGPathRelease(letters);
CFRelease(font);
CFRelease(line);
}

效果图

iOS之String动态书写的更多相关文章

  1. ios 开发中 动态库 与静态库的区别

    使用静态库的好处 1,模块化,分工合作 2,避免少量改动经常导致大量的重复编译连接 3,也可以重用,注意不是共享使用 动态库使用有如下好处: 1使用动态库,可以将最终可执行文件体积缩小 2使用动态库, ...

  2. 通过List<String>动态传递参数给 sqlcommand.Parameters

    通过List<String>动态传递参数 private void GetallChecked_TreeNote(TreeNodeCollection aNodes, ref int To ...

  3. 【转】提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果

    原文网址:http://www.zhimengzhe.com/IOSkaifa/37910.html MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单.方便,并且可以对显 ...

  4. iOS中关于动态Tableview中的cell数据传输的多线程问题解决之拙见

    iOS中关于动态Tableview中的cell数据传输的多线程问题解决之拙见 (2015-12-05 12:48:20)[编辑][删除] 转载▼     首先我们先明确一下问题: 1.因为UI是在主线 ...

  5. 李洪强iOS开发之动态获取UILabel的bounds

    李洪强iOS开发之动态获取UILabel的bounds 在使用UILabel存放字符串时,经常需要获取label的长宽数据,本文列出了部分常用的计算方法. 1.获取宽度,获取字符串不折行单行显示时所需 ...

  6. ios Objective-C的动态特性

    这是一篇译文,原文在此,上一篇文章就是受这篇文章启发,这次干脆都翻译过来. 过去的几年中涌现了大量的Objective-C开发者.有些是从动态语言转过来的,比如Ruby或Python,有些是从强类型语 ...

  7. ios ableviewcell的动态加载数据,模仿喜马拉雅动态数据加载

    iphone(UITableViewCell)动态加载图片http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Intr ...

  8. iOS: 学习笔记, 动态添加按钮

    1. 新建iOS -> Single View Application. 2. 个性控制器文件YYViewController.m(此处修改为你相应的控制器文件名) // // YYViewCo ...

  9. iOS 开发新版 动态库framework

    0. 参考 http://www.cocoachina.com/industry/20140613/8810.html framework+xib参考 : http://blog.csdn.net/x ...

随机推荐

  1. 码云的使用以及pycharm

    码云的使用 下载Git一路next 在码云上新建仓库 建立码云仓库 ​ 右键 git bash hero 依次输入 git config --global user.name "用户名&qu ...

  2. websocket接口测试

    1.先在jmeter的插件管理器安装webSocket的插件,WebSocket 常规选项解释如下: ip:测试服务器域名 Streaming Connection:请求之后是否保持连接,勾选之后在同 ...

  3. STM32---初学者用库函数好还是直接对寄存器操作比较好

    引用:http://blog.csdn.net/u010349006/article/details/416 首先,两个都是C语言.从51过渡过来的话,就先说寄存器操作.每个MCU都有自己的寄存器,5 ...

  4. Oracle学习01-Oracle的基本查询和过滤排序

  5. vue sChart组件使用页面一片空白问题及示例

    参考:https://www.ctolib.com/mip/lin-xin-vue-schart.html 在网上其他示例里,我试验后发现:渲染到<canvas id="myChart ...

  6. Thread-per-Message 这个工作交给你了

    Per是“每一”的意思,所以thread per message解释过来就是“每个消息一个线程”,message在这里可以看做是“命令”或“请求”的意思,对每隔命令或请求,分配一个线程,有这个线程执行 ...

  7. docker ps -a

    1 pwd 2 mkdir data 3 ll 4 uname -n 5 cd data/ 6 ll 7 pwd 8 ll 9 wget -N --no-check-certificate https ...

  8. String str = new String("abc"),这段代码一共生成了几个String对象?为什么?

    String str = new String("abc")创建了俩个对象,首先为创建一个String对象"abc",然后在调用String类的构造方法时 pu ...

  9. bzoj1433: [ZJOI2009]假期的宿舍 [二分图][二分图最大匹配]

    Description Input Output Sample Input 1 3 1 1 0 0 1 0 0 1 1 1 0 0 1 0 0 Sample Output ˆ ˆ HINT 对于30% ...

  10. Mysql优化系列之查询优化干货1

    从这一篇开始,准备总结一些直接受用的sql语句优化,写sql是第二要紧的,第一要紧的,是会分析怎么查最快, 因为当你写过很多sql后,查询出结果已经不是目标,快,才是目标.另外,通过测试和比较的结果才 ...