UIlabel
UILabel * label = [[UILabel alloc] Initwithframe:cgrectmake (10,30, Cgrectgetwidth (self.view.frame)-20, 200)];
Set text
Label.text = @ "Welcome to slam Dunk Master, I am Anxi coach";
Set Text color
Label.textcolor = [Uicolor Graycolor];
Default font size 17th
Label.font = [Uifont systemfontofsize:34];
Alignment
Label.textalignment = Nstextalignmentcenter;
Set Shadow
Label.shadowcolor = [Uicolor Redcolor];
Set shadow map size, default cgsizemake (0,-1)
Label.shadowoffset = Cgsizemake (-2,-2);
segmentation, display thumbnail
Label.linebreakmode = Nslinebreakbytruncatingtail;
Number of rows 0 is the number of automatically matched rows
Label.numberoflines = 1;
Whether the font fits in width (size is not valid)
Label.adjustsfontsizetofitwidth = YES;
Minimum font scale
Label.minimumscalefactor = 0.9;
Uifont
Output compiler-All fonts
For (NSString * familyname in [Uifont Familynames]) {
NSLog (@ "%@", familyname);
Nsarray * Familys = [Uifont fontnamesforfamilyname:familyname];
For (NSString * FontName in Familys) {
NSLog (@ "%@", FontName);
}
}
Concrete Implementation Method
Italic body
[Uifont italicsystemfontofsize:50];
Font Bold
[Uifont boldsystemfontofsize:50];
Set System font
[Uifont Systemfontofsize:10];
[Uifont fontwithname:@ "Heiti TC" size:25];
Rich Text
Paragraph settings
Nsmutableparagraphstyle * paragraph = [[Nsmutableparagraphstyle alloc] init];
paragraph.linespacing = 10;//Line Spacing
paragraph.paragraphspacing = 50;//segment Spacing
Paragraph.firstlineheadindent = 50;//First paragraph empty few lattice
Rich Text Implementation
Nsdictionary * dicta = @{nsfontattributename:[uifont systemfontofsize:20],
Nsforegroundcolorattributename:[uicolor greencolor],//Front View
Nsbackgroundcolorattributename:[uicolor graycolor],//Rear View
Nsparagraphstyleattributename:paragraph
nsobliquenessattributename:@0.5//Italic
Nsstrokecolorattributename:[uicolor Whitecolor],
nsstrokewidthattributename:@2,//Strokes
nskernattributename:@20,//Word Spacing
nsstrikethroughstyleattributename:@2,//Delete Line
nsunderlinestyleattributename:@1,//Underline
};
nsattributedstring * attribute = [[nsattributedstring alloc] initwithstring:examplestring attributes:dicta];
Variable Rich Text
nsmutableattributedstring * astring = [[Nsmutableattributedstring alloc] initwithstring:string];
Variable Rich Text
nsmutableattributedstring * Mutableattribute = [[Nsmutableattributedstring alloc] initwithstring:exmaplestring];
Nsrange Range1 = {0,3};
Nsrange range2 = {4,5};
[Mutableattribute addattribute:nsfontattributename Value:[uifont systemfontofsize:50] range:range1];
Nsdictionary * dict = @{nsforegroundcolorattributename:[uicolor Magentacolor],
Nsbackgroundcolorattributename:[uicolor Cyancolor]};
[Mutableattribute addattributes:dict Range:range2];
Append sub-string
nsattributedstring * string2 = [[Nsattributedstring alloc] initwithstring:@ "Good da! [Attributes:dict2];
[Astring Appendattributedstring:string2];
Calculate the height of a label
Be sure to first determine the width, and then calculate size-multi-line display based on width and font
Cgsize size = [string Boundingrectwithsize:cgsizemake (width, maxfloat) options:nsstringdrawinguseslinefragmentorigin Attributes:dict context:nil].size;
Single-line display
NSString * string = @ "Black Cat Sheriff";
Nsdictionary * dict = @{nsfontattributename:[uifont systemfontofsize:50]};
Cgsize size = [string sizewithattributes:dict];
Label Adaptive-MultiRow
UILabel * label = [[UILabel alloc] init];
Label.text = string;//give the string first, and then calculate its size
Label.numberoflines = 0;
Label.backgroundcolor = [Uicolor Greencolor];
Cgsize size = [Label Sizethatfits:cgsizemake (SELF.VIEW.FRAME.SIZE.WIDTH-40, maxfloat)];
Label.frame = CGRectMake (Size.width, size.height);
[Self.view Addsubview:label];
UILabel * label = [[UILabel alloc] Initwithframe:cgrectmake (self.view.frame.size.width-40, 0)];
Label.text = string;
Label.numberoflines = 0;
Label.backgroundcolor = [Uicolor Greencolor];
Be sure to set the width using SizeToFit
[Label SizeToFit];
[Self.view Addsubview:label];
iOS Learning Day3