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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:16:23+00:00 2026-06-09T02:16:23+00:00

I have a table view with hundreds of custom drawn UITableViewCells which are drawn

  • 0

I have a table view with hundreds of custom drawn UITableViewCells which are drawn using the drawRect: method. These cells all share the same color styles. So, in each drawRect:, I do something like this:

-(void)drawRect:(CGRect)rect
{
    UIColor *bgColor = [UIColor colorWithWhite:0.9 alpha:1.0];
    UIColor *textColor = [UIColor colorWithWhite:0.98 alpha:1.0];
    UIColor *strokeColor = [UIColor colorWithWhite:0.6 alpha:1.0];
    /* use colors */
}

And so as you’re scrolling down the table, this gets called hundreds of times. I’m not really sure if what I’m doing is efficient though. Is there a better way to create these colors, maybe with some reusability? Should I cache these colors in some global variable? Is what I am doing expensive or negligible?

  • 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-09T02:16:26+00:00Added an answer on June 9, 2026 at 2:16 am

    First you should profile with Instruments to see if a considerable amount of time is spent in these calls. If this is the case, then make them static variables and initialize them on first use:

    -(void)drawRect:(CGRect)rect
    {
        static UIColor *bgColor;
        static UIColor *textColor;
        static UIColor *strokeColor;
    
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            bgColor = [UIColor colorWithWhite:0.9 alpha:1.0];
            textColor = [UIColor colorWithWhite:0.98 alpha:1.0];
            strokeColor = [UIColor colorWithWhite:0.6 alpha:1.0];
        });
    
        /* use colors */
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table view controller with custom cells. In those cells i added
I have a table view of custom cells representing individual uploads and each cell
I have a table view which displays potentially hundreds of image thumbnails. The problem
I have a table view with numerous cells. When I press one, a tick
I have a table view with a custom cell ( UISwitch on every cell
I have a Table View Controller with cells. I want to update the text
I have a table view that has many cells. Each cell has its own
I have table view which is populated from an array grabbed from a url.
I have table view cells with cell image and text label and detailed label.
I have a table view and it is load from table view cells. But

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.