NSString text pixel length

How do I know how many pixels my text takes in UILabel?
I want to insert a small picture between the text.
It may be useful to change the width of the label.

+3
source share
3 answers

In NSString, added by UIKit, there are several methods that can give you the dimensions of a string if it is drawn. Full link here . The methods you care about are probably these:

  • sizeWithFont:
  • sizeWithFont: constrainedToSize:
  • sizeWithFont: constrainedToSize: lineBreakMode:
  • sizeWithFont: forWidth: lineBreakMode:
  • sizeWithFont: minFontSize: actualFontSize: forWidth: lineBreakMode:
+14

-[NSString sizeWithFont:] NSString(UIStringDrawing).

+2

take a look at this post Text pixel width in UILabel

+2
source

Source: https://habr.com/ru/post/1716987/


All Articles