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 = [
sizeWithFont:
someString
]; CGFloat strikeWidth = textSize.width;
yourFont
Comments
Post a Comment