iOS 7 sizeWithAttributes: replacement for sizeWithFont:constrainedToSize

前端 未结 9 1601
执笔经年
执笔经年 2020-11-28 01:31

How do you return a multiline text CGSize from the new iOS 7 method sizeWithAttributes?

I would like this to produce the same results as sizeWithFont:constrainedToSi

9条回答
  •  清酒与你
    2020-11-28 01:48

    If you have the text, font, numberOfLines and width of your label set, this method returns the size of your label:

    myLabel.numberOfLines = 0;
    
    CGSize size = [myLabel sizeThatFits:CGSizeMake(myLabel.frame.size.width, CGFLOAT_MAX)];`
    

提交回复
热议问题