In OC, the automatic calculation of the row height of the main call system
-(--boundingrectwithsize: ( Size options: (nsstringdrawingoptions) options Attributes: (nullable nsdictionary<nsstring *, id> *) Attributes Context: ( nullable nsstringdrawingcontext *) context Span class= "S4" >ns_available (10_11, 7_0)
< Span class= "S1" > < Span class= "S4" > under different iOS systems The height of the same font is different, so you cannot set a specific height value to limit
Workaround:
Label.text =@"Xijoaiogioaiogioioaig"; Label.numberoflines=2; Nsmutableparagraphstyle*style =[[Nsmutableparagraphstyle alloc]init]; Style.maximumlineheight= -; Style.minimumlineheight= -; CGRect rect= [Label.text boundingrectwithsize:cgsizemake (Screen_w- the, -*2) Options:nsstringdrawinguseslinefragmentorigin |nsstringdrawingusesfontleading Attributes:@{nsfontattributename:_comname.font,nsparagraphstyleattributename : style} Context:nil]; _height= Rect.size.height;
The following is an explanation of the method
The width of the Size:label or text display, usually set to Cgsizemake (100,maxfloat) If the width is fixed to a value of 100 when automatically calculating the width height is set to Cgsizemake (maxfloat,100) If the height is fixed to a value of 100 Set to a specific value if the width and height are ok
Options
Additional options when the text is drawn.
There are four types of:
1.NSStringDrawingTruncatesLastVisibleLine
2.NSStringDrawingUsesLineFragmentOrigin
3.NSStringDrawingUsesFontLeading
4.NSStringDrawingUsesDeviceMetrics
Typically NSStringDrawingUsesLineFragmentOrigin , the NSStringDrawingUsesLineFragmentOrigin entire text calculates the size of the entire text in a rectangle that consists of each line.
Nsstringdrawingusesfontleading the spacing between the fonts (leading, line spacing: From the bottom of the lines of text to the bottom of another line of text). ) to calculate.
NSStringDrawingTruncatesLastVisibleLineOr NSStringDrawingUsesDeviceMetric , the text size is calculated in terms of each word or glyph.
Attributes: Which property of the underlying text to calculate
Context: The text display of pixels generally pass nil using the system default
Note: When you use this method, the dynamic calculation height cannot be set Adjusttosize (this method is limited to one line)
iOS label auto-calculate line height