IOS Uilabel Detailed

Source: Internet
Author: User

UILabel Multiline Text wrapping (auto wrap)

1.UIView *footerview = [[UIView alloc] Initwithframe:cgrectmake (10, 100, 300, 180)];
2. UILabel *label = [[UILabel alloc] Initwithframe:cgrectmake (10, 100, 300, 150)];
3. Label.text = @ "Where is it?" Where is you? Where is you? Where is you? Where is you? Where is you? Where is you? Where is you? Where is you? Where is you? ";
4.//Clear background color
5. Label.backgroundcolor = [Uicolor Clearcolor];
6.//Set font color to white
7. Label.textcolor = [Uicolor Whitecolor];
8.//Text Center display
9. label.textalignment = Uitextalignmentcenter;
10.//Auto-fold line setting
Label.linebreakmode = Uilinebreakmodewordwrap;
Label.numberoflines = 0;
· Uilable is the most basic control of the iphone interface and is used primarily to display textual information.
• Common Properties and methods are:
1. Create
CGRect rect = CGRectMake (100, 200, 50, 50);
UILabel *label = [[UILabel alloc] initwithframe:rect];
2, text//set and read content, default to nil
Label.text = @ "text message"; Set content
NSLog (@ "%@", Label.text); Read content
3, TextColor//Set text color, default to Black
Lable.textcolor = [Uicolor Redcolor];
4, Font//Set the size of fonts, default 17
Label.font = [Uifont systemfontofsize:20]; ? general methods
Label.font = [Uifont boldsystemfontofsize:20]; Bold method
Label.font = [Uifont fontwithname:@ "Arial" size:16]; Specified
Method of Font
What's more? A way to import fonts from outside.
5, TextAlignment//Set label text alignment.
Label.textalignment = Nstextalignmentcenter; And also
Nstextalignmentleft, Nstextalignmentright.
6, NumberOfLines//tags display up to a maximum number of rows, or 0 for multiple lines.
Label.numberoflines = 2;
7, Enabled//only determines the way the label is drawn, set it
No will darken the text, indicating that it is not active, and setting a color value to it is not valid.
label.enable = NO;
8, highlighted//whether highlighting
label.highlighted = YES;
Label.highlightedtextcolor = [Uicolor Orangecolor]; Highlight
Text color when displayed
9, Shadowcolor//Set Shadow Color
[Label Setshadowcolor:[uicolor Blackcolor];
10, Shadowoffset//Set shadow Offset
[Label Setshadowoffset:cgsizemake (-1,-1)];
11, Baselineadjustment//If the Adjustsfontsizetofitwidth property is set
Set to Yes, this property controls the behavior of the text baseline.
Label.baselineadjustment = Uibaselineadjustmentnone;
Uibaselineadjustmentalignbaselines = 0, default, the top of the text is aligned with the centerline.
Uibaselineadjustmentaligncenters, the middle of the text is aligned with the label centerline.
Uibaselineadjustmentnone, the lowest end of the text is aligned with the label centerline.
12, autoshrink//whether automatic contraction
Fixed Font Size default, text size does not scale automatically if label width is less than text length
Minimumscalefactor sets the minimum shrinkage scale, if the label width is less than the text length, the text
Shrinks, shrinks beyond the proportions, and then stops shrinking.
Minimumfontsize sets the minimum shrink size, if the label width is less than the text length, the text size
Decrease, lower than the set font size, no longer decreases. 6.0 were no longer used later.
Label.minimumscalefactor = 0.5;
13, Adjustsletterspacingtofitwidth//change the spacing between letters to fit the label size
Mylabel.adjustsletterspacingtofitwidth = NO;
14, Linebreakmode//Set the display format when the text is too long
Label.linebreakmode = nslinebreakbycharwrapping; display units in characters
The following section is omitted.
Label.linebreakmode = nslinebreakbyclipping; cut in the same width as the text
The second part is removed.
Label.linebreakmode = nslinebreakbytruncatinghead; Front part text
To...... method is omitted, displaying the trailing text content.
Label.linebreakmode = nslinebreakbytruncatingmiddle; content in the middle
To...... The method is omitted, showing the text content of the kinsoku.
Label.linebreakmode = Nslinebreakbytruncatingtail; the contents of the ending section
To...... Method omitted to display the text content of the header.
Label.linebreakmode = nslinebreakbywordwrapping; display units in words
The following section is omitted.
15. Adjustsfontsizetofitwidth//Set font size to fit label width
Label.adjustsfontsizetofitwidth = YES;
16. Attributedtext: Sets the Label property text.
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;
17, vertical text display each text plus a line break, this is the most convenient and simple implementation.
Label.text = @ "please \ \ \ \ \ \ \ \ \ \ \ \ \ \"
Label.numberoflines = [Label.text length];



18, calculate the height of the Uilabel with the font after multiple lines
CGRect bounds = CGRectMake (0, 0, 200, 300);
Heightlabel = [MyLabel textrectforbounds:bounds
LIMITEDTONUMBEROFLINES:20]; The frame that calculates the label after 20 lines
NSLog (@ "%f", heightLabel.size.height);
19, Uilabel According to the number of words automatically realize the height of adaptation
UILabel *msglabel = [[UILabel alloc]
Initwithframe:cgrectmake (15, 45, 0, 0)];
Msglabel.backgroundcolor = [Uicolor Lighttextcolor];
[Msglabel setnumberoflines:0];
Msglabel.linebreakmode = Uilinebreakmodewordwrap;
Msglabel.font = [Uifont fontwithname:@ "Arial" size:12];
Cgsize size = Cgsizemake (290, 1000);
Msglabel.text = @ "Get the Devicetoken, we can use the WebService service to raise
to a. NET application, where I simply process it, print it directly, and copy it into a. NET application environment so that
Use. ";
Cgsize Msgsie = [Msglabel.text sizewithfont:fonts
Constrainedtosize:size];
[Msglabel setframe:cgrectmake (290, msgsie.height)];



20. Gradient Font Label
Uicolor *titlecolor = [Uicolor colorwithpatternimage:[uiimage
imagenamed:@ "Btn.png"];
NSString *title = @ "Setting";
UILabel *titlelabel = [[UILabel alloc]
Initwithframe:cgrectmake (0, 0, 80, 44)];
Titlelabel.textcolor = Titlecolor;
Titlelabel.text = title;
Titlelabel.font = [Uifont boldsystemfontofsize:20];
Titlelabel.backgroundcolor = [Uicolor Clearcolor];
[Self.view Addsubview:titlelabel];
[Titlelabel release];
21. Label Add border
TitleLabel.layer.borderColor = [[Uicolor graycolor] cgcolor];
TitleLabel.layer.borderWidth = 2;

IOS Uilabel Detailed

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.