Set multiple font color codes for a text segment in IOS

Source: Internet
Author: User

Set multiple font color codes for a text segment in IOS

This article mainly introduces how to set multiple font color codes for a text section in IOS, which is very practical. For more information, see.

Given the range and the color to be set, you can set different font colors for a text segment. The usage is as follows:

The Code is as follows:

[Self fuwenbenLabel: contentLabel FontNumber: [UIFont systemFontOfSize: 15] AndRange: NSMakeRange (6, 1) AndColor: RGBACOLOR (34,150,253, 1)];

The Code is as follows:

// Set different font colors

-(Void) fuwenbenLabel :( UILabel *) labell FontNumber :( id) font AndRange :( nsange) range AndColor :( UIColor *) vaColor

{

NSMutableAttributedString * str = [[NSMutableAttributedString alloc] initWithString: labell. text];

// Set the font size

[Str addattriename: NSFontAttributeName value: font range: range];

// Set the text color

[Str addattriename: NSForegroundColorAttributeName value: vaColor range: range];

Labell. attributedText = str;

}

The above is all the content of this article. I hope you will like it.

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.