zoukankan      html  css  js  c++  java
  • [翻译] BezierString

    BezierString

    https://github.com/lvnyk/BezierString

    Rendering NSAttributedStrings along arbitrary continuous UIBezierPaths

    将富文本沿着贝塞尔曲线绘制.

    Example

    1. Create a bezier path and an attributed string 创建出贝塞尔曲线以及富文本

    let bezierPath = UIBezierPath()
    bezierPath.moveToPoint(CGPointMake(50, 50+150))
    bezierPath.addCurveToPoint(CGPointMake(50+200, 50), controlPoint1: CGPointMake(50+10, 50+75), controlPoint2: CGPointMake(50+100, 50))
    bezierPath.addCurveToPoint(CGPointMake(50+400, 50+150), controlPoint1: CGPointMake(50+300, 50), controlPoint2: CGPointMake(50+400-10, 50+75))
    
    let attributedString = NSAttributedString(string: "Where did you come from, where did you go?", attributes: [
        kCTFontAttributeName: CTFontCreateWithName("HelveticaNeue-UltraLight", 26, nil),
        kCTForegroundColorAttributeName: UIColor.redColor().CGColor
        ])
    

    2. Use the BezierString class 使用BezierString类

    let bezierString = BezierString(bezierPath: bezierPath)
    
    // generate an image
    let img:UIImage! = bezierString.imageWithAttributedString(attributedString) 
    
    // or render onto a preexisting context
    bezierString.drawAttributedString(attributedString, toContext: UIGraphicsGetCurrentContext())
    

    UIBezierLabel

    Alternatively, in place of UILabel, use a UIBezierLabel instance, assign a bezierString orbezierPath and use as a normal UILabel

    需要注意的是,替换当前UILabel非常简单.使用UIBezierLabel的实体对象,然后给bezierPath赋值,其余地方使用起来跟正常UILabel一样.

    // create a label, either in code or Interface Builder
    let label = UIBezierLabel(frame: CGRectZero)
    
    // set the properties
    label.bezierPath = bezierPath
    label.textAlignment = .Center
    label.text = "Where did you come from, where did you go?"
    label.sizeToFit()
  • 相关阅读:
    静态和伪静态
    数据库优化
    C#数组的排序(正序逆序)
    C# for和 foreach 的数组遍历 比较
    Python识别璇玑图中诗的数量
    Linux环境下配置matplotlib库使用中文绘图
    manjaro配置记录
    ubuntu环境下测试cache大小并校验
    ubuntu 单机配置hadoop
    cachestat 安装文档
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/4792816.html
Copyright © 2011-2022 走看看