Search code examples
iosswiftfontstextkit

unexpected crash when using custom fonts with swift


i am trying to determine the size of attributedString with method

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

and thats my code

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

but i get this exception

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

but when i use system fonts .. it works good


Solution

  • Posting answer so others don't get confused:

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