Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8902997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:45:25+00:00 2026-06-15T01:45:25+00:00

I want to set two colors for UILabel’s text. I tried TTTRegexAttributedLabel , but

  • 0

I want to set two colors for UILabel's text. I tried TTTRegexAttributedLabel, but it is throwing unknown type error.

I tried following code too. But it is crashing at settext.

 NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Hello. That is a test attributed string."];
    [str addAttribute: @"Hello" value:[UIColor yellowColor] range:NSMakeRange(3,5)];
    [str addAttribute:@"That" value:[UIColor greenColor] range:NSMakeRange(10,7)];
    [str addAttribute:@"Hello" value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:20.0] range:NSMakeRange(20, 10)];

[syncStatusLabel setText:(NSString *)str];

Is there any other way to set multiple colors for single UILabel text?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:45:26+00:00Added an answer on June 15, 2026 at 1:45 am

    you can set text color with pattern image like bellow..

            [yourLable setTextColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"yourImageName"]]];
    

    and also set different color with this bellow code.. please check tutorial with detail mate..

    NSString *test = @"Hello. That is a test attributed string.";
    
     CFStringRef string =  (CFStringRef) test;
        CFMutableAttributedStringRef attrString = CFAttributedStringCreateMutable(kCFAllocatorDefault, 0);
        CFAttributedStringReplaceString (attrString,CFRangeMake(0, 0), string);
    
    
    
        /*
         Note: we could have created CFAttributedStringRef which is non mutable, then we would have to give all its
         attributes right when we create it. We can change them if we use mutable form of CFAttributeString.
         */
    
    
    
        //Lets choose the colors we want to have in our string
        CGColorRef _orange=[UIColor orangeColor].CGColor;
        CGColorRef _green=[UIColor greenColor].CGColor;
        CGColorRef _red=[UIColor redColor].CGColor;
        CGColorRef _blue=[UIColor blueColor].CGColor;    
    
    
    
    
        //Lets have our string with first 20 letters as orange
        //next 20 letters as green
        //next 20 as red
        //last remaining as blue
        CFAttributedStringSetAttribute(attrString, CFRangeMake(0, 20),kCTForegroundColorAttributeName, _orange);
        CFAttributedStringSetAttribute(attrString, CFRangeMake(20, 20),kCTForegroundColorAttributeName, _green);
        CFAttributedStringSetAttribute(attrString, CFRangeMake(40, 20),kCTForegroundColorAttributeName, _red);    
        CFAttributedStringSetAttribute(attrString, CFRangeMake(60, _stringLength-61),kCTForegroundColorAttributeName, _blue);
    

    for more information see this tutorial….

    coretext-tutorial-for-ios-part

    i hope this help you…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a problem, i want set text of a UILabel or UItextView or
I'm creating iOS app that has a label. I want to set two colors.
I have set the two buttons in preference.xml file. I want to go to
I want to implement two different dictionaries with a predefined set of valid keys.
I have two results from a data set. I want to add both results
I want set Listbox background to transparent but not working Is there any idea?
i want set class for repeater when doPostBack for those dataID i wan but
I have two things i want to do to this input text field. <input
I know you can set the BackgroundColor to alternate between two colors with a
if you want to set color for paint, you have two methods to use:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.