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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:50:41+00:00 2026-06-09T15:50:41+00:00

To add a UILabel to a table cell I use UILabel *timeLabel = [[UILabel

  • 0

To add a UILabel to a table cell I use

UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(270, 10, 40, 12)];
timeLabel.text = @"2s";
timeLabel.backgroundColor = [UIColor clearColor];
timeLabel.font = [UIFont systemFontOfSize:12];
timeLabel.textColor = [UIColor lightGrayColor];
timeLabel.highlightedTextColor = [UIColor whiteColor];
timeLabel.textAlignment = UITextAlignmentRight;
timeLabel.frame = CGRectIntegral(timeLabel.frame);
[cell.contentView addSubview:timeLabel]; 

in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath.

This works fine until I scroll the table or select a cell. Then the label becomes pixelated.

At load: enter image description here

after action: enter image description here

I also tried to add the label by subclassing UITableViewCell and load it in
- (void) layoutSubviews.

I already found related questions here and here but nothing worked.

EDIT: It’s not possible to use the standard cell labels since they’re already in use. I need to add an additional label.

  • 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-09T15:50:43+00:00Added an answer on June 9, 2026 at 3:50 pm

    I finally got it working with a dirty fix.

    In – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

    I set

    cell.selectionStyle = UITableViewCellSelectionStyleNone;.

    In a subclass of UITableViewCell I load the timeLabel in initWithStyle as follows:

    timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(270, 10, 40, 12)];
    timeLabel.text = @"2s";
    timeLabel.backgroundColor = [UIColor whiteColor];
    timeLabel.font = [UIFont systemFontOfSize:12];
    timeLabel.textColor = [UIColor lightGrayColor];
    timeLabel.highlightedTextColor = [UIColor whiteColor];
    timeLabel.textAlignment = UITextAlignmentRight;
    [self.contentView addSubview:timeLabel];
    

    then I override these two functions:

    #define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
    
    - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
    {
        if(highlighted == YES){
            UIImage *image = [UIImage imageNamed:@"cellBg@2x.png"];
            //scale custom cell background to necessary height
            UIImage *scaledImage = [image scaleToSize:CGSizeMake(1,self.contentView.frame.size.height)];
            //set cell background
            self.backgroundColor = [UIColor colorWithPatternImage:scaledImage];
            //set textcolor for default labels
            self.textLabel.textColor = [UIColor whiteColor];
            self.detailTextLabel.textColor = [UIColor whiteColor];
            //set textcolor for custom label
            timeLabel.textColor = [UIColor whiteColor]; 
            //cope background for custom label background since timeLabel.backgroundColor = [UIColor clearColor] doesnt work
            CGImageRef ref = CGImageCreateWithImageInRect(scaledImage.CGImage, CGRectMake(0, 10, 12, 20));
            UIImage *img = [UIImage imageWithCGImage:ref];
            //set custom label background
            timeLabel.backgroundColor = [UIColor colorWithPatternImage:img];
        } else {
            //set unselected colors
            self.backgroundColor = [UIColor whiteColor];
            self.textLabel.textColor = [UIColor darkGrayColor];
            self.detailTextLabel.textColor = UIColorFromRGB(0x808080);
            timeLabel.textColor = UIColorFromRGB(0x808080);
            //white background works without the label pixelates
            timeLabel.backgroundColor = [UIColor whiteColor];
        }
    }
    
    - (void)setSelected:(BOOL)selected animated:(BOOL)animated
    {
        if(selected == YES){
            UIImage *image = [UIImage imageNamed:@"cellBg@2x.png"];
            UIImage *scaledImage = [image scaleToSize:CGSizeMake(1,self.contentView.frame.size.height)];
            self.backgroundColor = [UIColor colorWithPatternImage:scaledImage];
            self.textLabel.textColor = [UIColor whiteColor];
            self.detailTextLabel.textColor = [UIColor whiteColor];
            timeLabel.textColor = [UIColor whiteColor];
            CGImageRef ref = CGImageCreateWithImageInRect(scaledImage.CGImage, CGRectMake(0, 10, 12, 20));
            UIImage *img = [UIImage imageWithCGImage:ref];  
            timeLabel.backgroundColor = [UIColor colorWithPatternImage:img];
        } else {
            self.backgroundColor = [UIColor whiteColor];
            self.textLabel.textColor = [UIColor darkGrayColor];
            self.detailTextLabel.textColor = UIColorFromRGB(0x808080);
            timeLabel.textColor = UIColorFromRGB(0x808080);
            timeLabel.backgroundColor = [UIColor whiteColor];
        }
    }
    

    hope this helps some people!

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

Sidebar

Related Questions

I add a label on to the view UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0f,
How do I add a black outline to my white UILabel text?
I want to add GillSans-Bold font to a UILabel. I have set it in
Why can't I add a subview to table view cell's content view? - (UITableViewCell
hi i am trying to add uilabel in a group table .The approach i
I have a tableView where I add UILabel's to cell contentView as subview in
I'm trying to add a UILabel to my UIScrollView , but it doesn't show
I have these Views on which I add UILabels as text, The Views can
I want to add a custom table to my iPhone app, that should look
I am trying to add a UILabel anagrammatically like below - (void)viewDidLoad { [super

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.