iOS developing calculated text size

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.