In the development of iOS, such as Weibo, QQ chat interface to display a large number of text messages, so that the size of the text needs to be calculated in order to design the appropriate control size and location. Here's how iOS 7.0 calculates the text size.
-(CGRect) Boundingrectwithsize: (cgsize) Size options: (nsstringdrawingoptions) Options attributes: (Nsdictionary * ) Attributes Context: (Nsstringdrawingcontext *) Context Ns_available_ios (7_0);
This is an object method of NSString, and when a string instance calls the method, the method returns a CGRect type of data through the parameters passed in, which is the size of the text at which the string is displayed.
Size: Limits dimensions that are used to calculate the rectangular blocks that are occupied when the text is drawn, such as SIZE.W not exceeding SCENCE.W in the development of Weibo. You can set Size.y to infinity Maxfloat to make it easier to display all text content.
Option: Additional options when text is drawn. There are four types of
: 1. Nsstringdrawingtruncateslastvisibleline 2.NSStringDrawingUsesLineFragmentOrigin
3. Nsstringdrawingusesfontleading
4. Nsstringdrawingusesdevicemetrics
typically uses nsstringdrawinguseslinefragmentorigin, If the options parameter is Nsstringdrawinguseslinefragmentorigin, the entire text calculates the size of the entire text in a rectangle that consists of each line.
Attributes: Uifront the text into a dictionary. For example, nsdictionary *dict = @{nsfontattributename:font}
Context:context context. Includes information such as how to adjust word spacing and zoom. Eventually, the object contains information that will be used for text drawing. This parameter can be nil.