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: