The class libraries encapsulated by others are used to display the words of multiple colors on the same UILable.
The class library can be downloaded directly from the blog. Do not forget to leave a message after the download.
Class Library usage: Mainly used in CoreText. Therefore, you need to reference the CoreText system framework before using the class library.
Note that this encapsulated class library does not support ARC
After the class library is set, start using the methods in this library:
// Do any additional setup after loading the view, typically from a nib.
/*
Note: The color value must be predefined by the system.
+ (UIColor *) blackColor; // 0.0 white
+ (UIColor *) darkGrayColor; // 0.333 white
+ (UIColor *) lightGrayColor; // 0.667 white
+ (UIColor *) whiteColor; // 1.0 white
+ (UIColor *) grayColor; // 0.5 white
+ (UIColor *) redColor; // 1.0, 0.0, 0.0 RGB
+ (UIColor *) greenColor; // 0.0, 1.0, 0.0 RGB
+ (UIColor *) blueColor; // 0.0, 0.0, 1.0 RGB
+ (UIColor *) cyanColor; // 0.0, 1.0, 1.0 RGB
+ (UIColor *) yellowColor; // 1.0, 1.0, 0.0 RGB
+ (UIColor *) magentaColor; // 1.0, 0.0, 1.0 RGB
+ (UIColor *) orangeColor; // 1.0, 0.5, 0.0 RGB
+ (UIColor *) purpleColor; // 0.5, 0.0, 0.5 RGB
+ (UIColor *) brownColor; // 0.6, 0.4, 0.2 RGB
+ (UIColor *) clearColor; // 0.0 white, 0.0 alpha
Otherwise, the program will crash.
*/
NSString * text = @ "Hello <font color = \" red \ "> core text <font color = \" blue \ "> world! \ NHello <font color = \ "lightGray \"> core text <font color = \ "green \"> world! "; // [NSString stringWithContentsOfFile: path encoding: NSUTF8StringEncoding error: NULL];
MarkupParser * p = [[MarkupParseralloc] init] autorelease];
NSAttributedString * attString = [p attrStringFromMarkup: text];
[Self. customLabelsetAttString: attString];
Explanation: customLabel is the custom CustomLable In the encapsulation class library. I drag the control directly here. If you use it, you can first create an instance and then use it.
Multiple colors mainly use HTML tags. MarkupParser aims to identify these tags.
Download the class library