How to get height for NSAttributedString at a fixed width

后端 未结 12 1116
萌比男神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:32

    The answer is to use
    - (void)drawWithRect:(NSRect)rect options:(NSStringDrawingOptions)options
    but the rect you pass in should have 0.0 in the dimension you want to be unlimited (which, er, makes perfect sense). Example here.

提交回复
热议问题