Calculating the CGSize of an NSString

Send Snippet To: Save this snippet to Code Collector Pro -- view all powidl's snippets
language: Objective-C
license: Other

Code for Snippet:

                
UIFont *myFont = [UIFont boldSystemFontOfSize:15.0];
// Get the width of a string ...
CGSize size = [@"Some string here!" sizeWithFont:myFont];
 
// Get the width of a string when wrapping within a particular width
NSString *loremIpsum = @"Lorem Ipsum Delores S...";
CGSize size = [loremIpsum sizeWithFont:myFont
                              forWidth:150.0
		                lineBreakMode:UILineBreakModeWordWrap];
comments powered by Disqus

Info

Link to this snippet:


Download to Code Collector

To use the direct link to your snippet on CodeCollector.net either copy the html from the above section or drag the Download to Code Collector to where you would like to use it.

More Info:

Times Viewed: 634
Date Added: 2009-03-02 10:45:41
Last Modified: 0000-00-00 00:00:00

Web Analytics