How to use Ios--uilabel details
Use of Uilabel
UILabel *onelabel = [[UILabel alloc] init];
The most frequently used
Onelabel.frame = CGRectMake (0, 0, 320, 200); Setting the location and size of the Onelabel
Onelabel.text = @ "I am a uilabel oh,"; Set the word onelabel display
Onelabel.textcolor = [Uicolor blackcolor]; Set Font Color
Onelabel.backgroundcolor = [Uicolor Redcolor]; Set Background color
Onelabel.backgroundcolor = [Uicolor Clearcolor]; You can set a transparent background color
Onelabel.alpha = 1.0; Set transparency (range is between 0.0-1.0)
Font and font size
Onelabel.font = [Uifont fontwithname:@ "Helvetica" size:25.4f]; Sets the font and size of the displayed words, and when the font does not exist, the size is also invalid
Onelabel.font = [Uifont systemfontofsize:35.0f]; Set Font size only
Onelabel.font = [Uifont boldsystemfontofsize:35.0f]; Sets the font size and is bold
Onelabel.textalignment = Nstextalignmentcenter; Set the display position of the font: left, center, right
Onelabel.adjustsfontsizetofitwidth = YES; Set the font size to automatically fit the height
onelabel.userinteractionenabled = YES; Set whether you can interact with users
onelabel.enabled = YES; Sets whether the text of the Onelabel can be changed, by default Yes
Set the number of rows, provided that the height is sufficient
Set the number of rows to 0, you can calculate the height width of the corresponding text according to the text, full display, the default single row display
Onelabel.numberoflines = 3;
Set whether you can highlight
onelabel.highlighted = YES;
Onelabel.highlightedtextcolor = [Uicolor Redcolor];
Set Shadow
Onelabel.shadowcolor = [Uicolor Graycolor];
Onelabel.shadowoffset = Cgsizemake (2.0, 2.0);
Set the display format when text is too long
Onelabel.linebreakmode = nslinebreakbyclipping;
typedef ns_enum (Nsinteger, Nslinebreakmode) {
nslinebreakbywordwrapping = 0,
Nslinebreakbycharwrapping,
Nslinebreakbyclipping,
Nslinebreakbytruncatinghead,
Nslinebreakbytruncatingtail,
Nslinebreakbytruncatingmiddle
// }
If the Adjustsfontsizetofitwidth property is set to Yes, this property controls the behavior of the text baseline
Onelabel.baselineadjustment = Uibaselineadjustmentalignbaselines;
typedef enum {
Uibaselineadjustmentalignbaselines,
Uibaselineadjustmentaligncenters,
Uibaselineadjustmentnone,
} uibaselineadjustment;
Add Onelabel to view and free up memory
[Self.view Addsubview:onelabel];
[Onelabel release], Onelabel = nil;
Report:
NSLog (@ "%@", [Uifont familynames]); Can print out all the fonts that exist
How to use Ios--uilabel details