UILable: Display multiple colors

Source: Internet
Author: User

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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.