【问题标题】:unexpected crash when using custom fonts with swift快速使用自定义字体时出现意外崩溃
【发布时间】:2017-01-18 00:32:03
【问题描述】:

我正在尝试用方法确定属性字符串的大小

func boundingRect(with size: CGSize, options: NSStringDrawingOptions = [], context: NSStringDrawingContext?) -> CGRect

这就是我的代码

paragraphRect = finalString.boundingRect(with: CGSize(width:textViewExample.frame.size.width - 10, height: CGFloat(CGFloat.greatestFiniteMagnitude)), options: ([.usesLineFragmentOrigin,.usesFontLeading]), context: nil)

但我得到了这个异常

-[_SwiftValue renderingMode]: unrecognized selector sent to instance 0x600000050110

但是当我使用系统字体时..效果很好

【问题讨论】:

    标签: ios swift fonts textkit


    【解决方案1】:

    发布答案以免其他人感到困惑:

    UIFont(name: UIFont.lightFontName(), size: 14)!
    

    【讨论】:

      【解决方案2】:

      使用自定义字体然后字体应该被解包:

      UIFont(name: UIFont.lightFontName(), size: 14)!
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-02-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-13
        • 1970-01-01
        相关资源
        最近更新 更多