Detailed description of automatically calculated rows for ios label and high description of ioslabel rows

Source: Internet
Author: User

Detailed description of automatically calculated rows for ios label and high description of ioslabel rows

Automatically calculates the main invocation system of the Row Height in OC.

-(-- Attributes :( CGSize) size options :( optional) options attributes :( nullable NSDictionary <NSString *, id> *) attributes context :( nullable NSStringDrawingContext *) context NS_AVAILABLE (10_11, 7_0 );

In different ios systems, the height and size of the same font are different. Therefore, you cannot set a specific height value.

Solution:

    label.text = @"xijoaiogioaiogioioaig";    label.numberOfLines = 2;    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];    style.maximumLineHeight = 20;    style.minimumLineHeight = 20;    CGRect rect = [label.text boundingRectWithSize:CGSizeMake(Screen_W - 125, 20*2) options: NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:_comName.font,NSParagraphStyleAttributeName:style} context:nil];    _height = rect.size.height;

 

 

 

The following is a detailed description of this method.

Size: label or text display width and height. Generally, when the width is calculated automatically, if the width is fixed to a value of 100, it is set to CGSizeMake (100, MAXFLOAT) if the height is fixed to a value of 100, it is set to CGSizeMake (MAXFLOAT, 100). If both width and height are determined, they are set to specific values.

 

Options:

Additional options for text painting.
There are four types:
1.NSStringDrawingTruncatesLastVisibleLine
2.NSStringDrawingUsesLineFragmentOrigin
3.NSStringDrawingUsesFontLeading
4.NSStringDrawingUsesDeviceMetrics
GenerallyNSStringDrawingUsesLineFragmentOrigin,NSStringDrawingUsesLineFragmentOriginThe size of the entire text is calculated in the unit of a rectangle consisting of each line.

NSStringDrawingUsesFontLeading is the line spacing between fonts (leading, line spacing: the distance from the bottom of a line of text to the bottom of another line of text .) .

NSStringDrawingTruncatesLastVisibleLineOrNSStringDrawingUsesDeviceMetric, The text size is calculated in units of each word or font.

Attributes: which attribute of the basic text is used for calculation?

Context: text display pixels are generally transmitted to nil by default.

Note: When this method is used, the height of dynamic calculation cannot be set to adjustToSize (this method is limited to one row)

 

 

 



 

 

 

Related Article

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.