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
,NSStringDrawingUsesLineFragmentOrigin
The 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 .) .
NSStringDrawingTruncatesLastVisibleLine
OrNSStringDrawingUsesDeviceMetric
, 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)