How to know how much pixels my text is taking in a UILabel ?
I want to insert a small picture in between text.
Can be usefull to adjust my label width.
views:
448answers:
3
+5
A:
There are a few methods in NSString added by UIKit that can give you the dimensions of the string if it were to be drawn. The full reference is here. The methods you care about are probably these:
- sizeWithFont:
- sizeWithFont:constrainedToSize:
- sizeWithFont:constrainedToSize:lineBreakMode:
- sizeWithFont:forWidth:lineBreakMode:
- sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:
Kevlar
2009-09-05 22:12:32
+2
A:
-[NSString sizeWithFont:]
is part of NSString(UIStringDrawing)
.
Graham Lee
2009-09-05 22:12:34
+2
A:
take a look at this post http://stackoverflow.com/questions/1340667/pixel-width-of-the-text-in-a-uilabel
Steve918
2009-09-05 22:12:48