前两天下载了一个Swift的HUD提示效果,偶然发现其中的提示效果上面的文字是动态书写的。感觉挺不错的,代码地址如下:
http://code.cocoachina.com/view/129442。
然后自己使用里面部分技术写了一个OC版的,
Demo地址:https://github.com/longitachi/WritingEffect/tree/master
效果图:
Swift具体实现(仅仅贴出NSString转UIBezierPath的方法,动画简单自己加,或者下载源码):
class func bezierPathFrom(string:String) -> UIBezierPath{
let paths = CGPathCreateMutable()
let fontName = __CFStringMakeConstantString("SnellRoundhand")
let fontRef:AnyObject = CTFontCreateWithName(fontName,18,nil)
let attrString = NSAttributedString(string: string,attributes: [kCTFontAttributeName as String : fontRef])
let line = CTLineCreateWithAttributedString(attrString as CFAttributedString)
let runA = CTLineGetGlyphRuns(line)
for (var runIndex = 0; runIndex < CFArrayGetCount(ru