How do I set the font size in a text cell so that the string fills the cell's rect?

后端 未结 6 1386
刺人心
刺人心 2020-12-30 15:13

I have a view that contains two NSTextFieldCells. The size at which these cells are drawn is derived from the size of the view, and I want the text in each cell

6条回答
  •  太阳男子
    2020-12-30 15:56

    Two ideas. One I've tried, the other might work:

    1) Do like in this question: How to truncate an NSString based on the graphical width? i.e. just try out different sizes until it doesn't fit anymore

    2) Create the cell, give it the maximum rect and set it to fit its text into the cell, then ask it for its ideal size (there's a method on there that does that) then resize the cells again. At last if I understood your problem correctly.

提交回复
热议问题