By using rich text to make a string of different fonts, different word spacing, different colors of the settings
1. The following is the instance code
I encapsulated a method that can be called directly
-(void) Label: (UILabel *) label Andwithtext: (NSString *) text Andfont: (uifont *) font Andleftcolor: (Uicolor *) Leftcolor Andrightcolor: (Uicolor *) Rightcolor Andnumber: (long) Number andleftrangenummber: (Nsinteger) leftnumber{
Create Rich Text
nsmutableattributedstring * labelstring = [[Nsmutableattributedstring alloc] Initwithstring:[nsstring stringwithformat:@ "%@", text]];
Rich-Text fonts
[Labelstring addattribute:nsfontattributename Value:font range:nsmakerange (0, labelstring.length)];
Font color to the left of rich text
[Labelstring addattribute:nsforegroundcolorattributename Value:kscriptgraycolor range:NSMakeRange (0, LeftNumber)];
Font color to the right of rich text
[Labelstring addattribute:nsforegroundcolorattributename Value:kscriptblackcolor range:NSMakeRange (LeftNumber, Labelstring.length-leftnumber)];
Set word spacing to the left of rich text
Cfnumberref num = cfnumbercreate (kcfallocatordefault,kcfnumbersint8type,&number);
[Labelstring AddAttribute: (ID) kctkernattributename value: (__bridge ID) num range:nsmakerange (0,leftnumber-2)];
Cfrelease (num);
[Label Setattributedtext:labelstring];
}
2. For example, if you want to create a string with rich text, you can call the method directly.
[Self Label:self.hospitalLabel andwithtext:@ "hospital: 123" Andfont:[uifont fontwithname:kfontpingfangmedium Size: Kfitfontsize (+)] Andleftcolor:kscriptgraycolor andrightcolor:kscriptblackcolor andnumber:20.0f Andleftrangenummber:3];
3. The implementation of the specific example image is as follows:
About iOS Rich Text usage