IOS How to calculate the width of a text string

NSString *someString = @"Hello World";
UIFont *yourFont = // [UIFont ...]
CGSize stringBoundingBox = [someString sizeWithFont:yourFont];

iOS 7

CGSize textSize = [someString sizeWithAttributes:@{NSFontAttributeName:yourFont}];

CGFloat strikeWidth = textSize.width;

iOS <7

Prior to iOS7, you had to use the sizeWithFont: method.
CGSize textSize = [someString sizeWithFont:yourFont];

CGFloat strikeWidth = textSize.width;
 

Comments

Popular posts from this blog

Java : Variables Declaring

Install DNF in RHEL/CentOS 7

SQL Self JOIN