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 7999919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:38:29+00:00 2026-06-04T15:38:29+00:00

I got a requirements to display a UILabel with background split between two colors,

  • 0

I got a requirements to display a UILabel with background split between two colors, like in this image:

enter image description here

(colors here are black at the bottom and 50% gray at the top – but this is not important). I tried setting the label’s background colour to 50% grey in the interface builder and then do this in the code:

CALayer *sl1 = [[[CALayer alloc] init] autorelease];
sl1.frame = CGRectMake(0, lbl.frame.size.height / 2, lbl.frame.size.width, score1.frame.size.height/2);
sl1.backgroundColor = [[UIColor blackColor] CGColor];
[lbl.layer insertSublayer:sl1 atIndex:0];

Unfortunately, this resulted in the black part being drawn over the text, so the label looks like this:

enter image description here

which is, needless to say, is not something I need. So how can I get this background without turning to custom images? The issue is I need to have UILabel‘s like this in several places, different sizes – so I would need to create multiple versions of the background image.

Any ideas? Thanks.

  • 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-04T15:38:32+00:00Added an answer on June 4, 2026 at 3:38 pm

    this works:

    UILabel* myLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 50)];
    myLabel.text = @"Ciao";
    myLabel.textColor = [UIColor greenColor];
    
    UIGraphicsBeginImageContext(CGSizeMake(100, 50));   
    CGContextRef context = UIGraphicsGetCurrentContext();
    // drawing with a gray fill color
    CGContextSetRGBFillColor(context,  0.4, 0.4, 0.4, 1.0);
    // Add Filled Rectangle, 
    CGContextFillRect(context, CGRectMake(0.0, 0.0, 100, 50));
    
    // drawing with a black fill color
    CGContextSetRGBFillColor(context,  0., 0., 0., .9);
    // Add Filled Rectangle, 
    CGContextFillRect(context, CGRectMake(0.0, 25, 100, 25));
    
    UIImage* resultingImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    myLabel.backgroundColor = [UIColor colorWithPatternImage:resultingImage];
    [self.view addSubview:myLabel];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a css menu like this: <ul> <li><a>Item1</a></li> <li><a>Item Two</a></li> <li><a>Item C</a></li> <li><a>A
I've got some complicated requirements and wondered if there's a way to accomplish this
This is my requirement in Android . I need to display a tiny image.
I got requirements- 1. Have random values in a List/Array and I need to
I've got a program where a lot of classes have really complicated configuration requirements.
I got the requirement like, In a page there will be 4 panels which
I am using datalist to display data from the database,I have got three fields
I got the requirement to display output from an IP camera to the webpage
OK, so I have this image that's 1000x500. So I'm displaying it in WP7
hi i am creating app to display ads at bottom. i am done all

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.