开发者

a generic function to find height for label by passing the string that the label is to be populated

i need to find heigh开发者_如何转开发t for a label with certain text based on its font and length. It requires to be generic to hold font as well as a parameter.


To get the height of a NSString object using sizeWithFont: method.

NSString *theText = myLabel.text;
CGFloat width = myLabel.frame.size.width ;
CGSize theSize = [theText sizeWithFont:myLabel.font constrainedToSize:CGSize(width,MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];

Here is the height of your UILabel .

CGFloat myLabelHeight = theSize.height;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜