Uilabel of IOS Components

Source: Internet
Author: User
Tags truncated

Common attributes and methods of uilabel:

// Create a uilabel object

Uilabel * label = [[uilabel alloc] initwithframe: Self. View. bounds];

// Set the display text

Label. Text = @ "This Is A uilabel demo ,";

// Set the text font

Label. font = [uifont fontwithname: @ "Arial" Size: 35];

// Set the text color

Label. textcolor = [uicolor yellowcolor];

// Set the text horizontal display position

Label. textalignment = uitextalignmentcenter;

// Set the background color

Label. backgroundcolor = [uicolor bluecolor];

// Set the word Folding Method

Label. linebreakmode = uilinebreakmodewordwrap;

// Set whether the label can display multiple rows. If the value is 0, multiple rows are displayed.

Label. numberoflines = 0;

// Dynamically sets the uilabel height based on the Content size.

Cgsize size = [label. Text sizewithfont: Label. Font constrainedtosize: Self. View. bounds. Size linebreakmode: Label. linebreakmode];

Cgrect rect = label. frame;

Rect. Size. Height = size. height;

Label. Frame = rect;

I have attached various uilinebreakmode situations, but I have not tried them one by one.

Typedef Enum {
Uilinebreakmodewordwrap = 0,
Uilinebreakmodecharacterwrap,
Uilinebreakmodeclip,
Uilinebreakmodeheadtruncation,
Uilinebreakmodetailtruncation,
Uilinebreakmodemiddletruncation,
} Uilinebreakmode;

Uilinebreakmodewordwrap = 0,
Line feed in units of words, truncated in units.
Uilinebreakmodecharacterwrap,
Line feed in characters, truncated in characters.
Uilinebreakmodeclip,
Line feed in words. Truncation in characters.
Uilinebreakmodeheadtruncation,
Line feed in words. If it is a single row, the start part has a ellipsis. If there are multiple rows, there is a ellipsis in the middle, and there are 4 characters after the ellipsis.
Uilinebreakmodetailtruncation,
Line feed in words. Whether it is a single row or multiple rows, there is a ellipsis at the end.
Uilinebreakmodemiddletruncation,
Line feed in words. Whether it is a single line or multiple lines, there are ellipsis in the middle, and there are only two characters behind the ellipsis.


Special effects:

1. Vertical text display

To achieve this effect, netizens have provided four methods:

1.1 rotate uilabel. This method is not optional. The orientation of each font after rotation is still problematic.

1.2 add a line break to each text, which is the most convenient and simple implementation method.

Label. Text
= @ "Please \ n vertical \ n straight \ n party \ n Direction \ n row \ n column ";

Label. numberoflines = [label. Text length];

1.3 create a new canvas and draw vertical lines of text on uilabel.

1.4 rewrite the uilabel class and add the vertical bar text display function.

Reference http://www.cnblogs.com/salam/archive/2012/05/31/UILabel.html


Bold text effect:
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.