Stretching and kerning type, not working in Storyboard with @IBDesignable

﹥>﹥吖頭↗ 提交于 2019-11-29 16:19:23

You should also put your code inside prepareForInterfaceBuilder(). It's called only in interface builder and not at runtime.

override func prepareForInterfaceBuilder() {
    let ats = NSMutableAttributedString(string: self.text!)
    let rg = NSRange(location: 0, length: self.text!.characters.count)

    ats.addAttribute(
        NSKernAttributeName, value:CGFloat(tracking), range:rg )

    ats.addAttribute(
        NSExpansionAttributeName, value:CGFloat(stretching), range:rg )

    self.attributedText = ats
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!