[sourcecode lang=”objc”]
– (CGFloat)widthOfString:(NSString *)string withFont:(UIFont *)font {
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:font, kCTFontAttributeName, nil];
return [[[NSAttributedString alloc] initWithString:string attributes:attributes] size].width;
}
[/sourcecode]
Leave a Reply