How to get height for NSAttributedString at a fixed width

后端 未结 12 1073
萌比男神i
萌比男神i 2020-12-12 18:53

I want to do some drawing of NSAttributedStrings in fixed-width boxes, but am having trouble calculating the right height they\'ll take up when drawn. So far, I\'ve tried:

12条回答
  •  自闭症患者
    2020-12-12 19:36

    I found helper class to find height and width of attributedText (Tested code)

    https://gist.github.com/azimin/aa1a79aefa1cec031152fa63401d2292

    Add above file in your project

    How to use

    let attribString = AZTextFrameAttributes(attributedString: lbl.attributedText!)
    let width : CGFloat = attribString.calculatedTextWidth()
    print("width is :: >> \(width)")
    

提交回复
热议问题