Common properties of uilabel: summary of IOS development


1. Text: set label display text.

2. Attributedtext: set label attribute text.

IOS code

NSString *text = @"first"; 
NSMutableAttributedString *textLabelStr = [[NSMutableAttributedString alloc] initWithString:text]; 
[textLabelStr setAttributes:@{NSForegroundColorAttributeName : [UIColor lightGrayColor], 
 NSFontAttributeName : [UIFont systemFontOfSize:17]} range:NSMakeRange(11, 10)];
label.attributedText = textLabelStr; 

3. Font: set label text font.

The default font size is 17.

IOS code

label.font = [UIFontsystemFontOfSize:17]
label.font = [UIFont fontWithName:@"Arial" size:16]; 

IOS code

label.textColor = [UIColor blueColor];

4. Textalignment: set label text alignment.

IOS code

label.textAlignment = NSTextAlignmentCenter; 

5. Linebreakmode: set the display mode when the label text is too long. This property is used for line breaking and truncation of the text in the label.

First, numberoflines must be set to 0 to have an effect.

IOS code

label.lineBreakMode  =Nslinebreakbycharwrapping; displays in characters, and omits the following parts. 
label.lineBreakMode  =It is the same length as the last half of the text. 
label.lineBreakMode  =Nslinebreakbytruncatinghead; in front of the text to The method is omitted and the content of the tail text is displayed. 
label.lineBreakMode  =Nslinebreakbytruncatingmiddle; the content in the middle is The method is omitted and the text content at the beginning and the end is displayed. 
label.lineBreakMode  =Nslinebreakbytruncatingtail; ends with Mode is omitted, and the text content of the header is displayed. 
label.lineBreakMode  =Nslinebreakbywordwrapping; is displayed in words, and the following parts are omitted and not displayed.

For example:

label.numberOfLines = 0 label.lineBreakMode = NSLineBreakByTruncatingMiddle;

Implementation effect:

6. Enabled: set whether the text content is changeable.

7. Adjustsfontsizetofitwidth: text content adaptive label width.

8. Adjustsletter spacing to fit width: adapts the label width according to the interval of letters, and the excess part is Display.

9. Numberoflines: the maximum number of lines displayed in the label.

10. Minimumscalefactor: set the minimum font, which is the same as minimumfontsize. Minimumfontsize cannot be used after IOS 6.

11. Highlightedtextcolor: set the text highlight color to use with highlighted.

12. Shadowcolor: set the text shadow color.

13. Shadowcolor: set the offset between the text shadow and the original text. label.shadowOffset= Cgsizemake (1.0, 5.0); 14. Userinteraction enabled: set whether to ignore or remove user interaction. The default is No.

15. Preferred maxlayout width: the maximum width of the label layout is preferred.

16. Baselineadjustment: if the adjustsfontsizetofitwidth property is set to yes, this property controls the behavior of the text baseline.

IOS code

label4.baselineAdjustment = UIBaselineAdjustmentNone; 
Uibaselineadjustmentalignbaselines = 0, by default, the top of the text is aligned with the center line. 
Uibaseline adjustment alignment centers, the center line of the text is aligned with the center line of the label. 
Uibaseline adjustment none, the lowest end of the text is aligned with the center line of the label.

17. BackgroundColor background color

IOS Code: clear background color label1. BackgroundColor = [uicolor clearcolor];

The common properties of uilabel in the above summary of IOS development are all the contents shared by Xiaobian. I hope I can give you a reference, and I hope you can support developeppaer more.