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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:55:34+00:00 2026-06-04T22:55:34+00:00

for my tableview I’ve done a custom background view which I call on viewDidLoad

  • 0

for my tableview I’ve done a custom background view which I call on viewDidLoad on each tableView on my project:

- (void)viewDidLoad{
    [super viewDidLoad];
    //other unrelated sutff
    self.tableView.backgroundView=[[BlueStyleBackground alloc]init];
}

It was my understanding that doing quartz2D stuff was the best option performance-wise. However this background view takes 0.45 seconds (average) to get drawn. This makes all the naviagation among tableViews a bit slow, not much but enough to notice it.

The background view is a gradient with a pattern overlaped. I’ve found out that the gradient gets drawn in 0.12 seconds, so the bottle neck appears to be the pattern drawing. What surprises me is that, from my point of view, it doesn’t seem like a complicated thing to draw, it’s only one horizontal line with a shadow.

Here is how the pattern is called (inside recDraw):

static const CGPatternCallbacks callbacks = { 0, &MyDrawColoredPattern2, NULL };

CGContextSaveGState(context);
CGColorSpaceRef patternSpace = CGColorSpaceCreatePattern(NULL);
CGContextSetFillColorSpace(context, patternSpace);
CGColorSpaceRelease(patternSpace);


CGPatternRef pattern = CGPatternCreate(NULL,
                                         rect,//superficie que ha de cobrir CGRectMake(0, 0,self.bounds.size.width,8),
                                       CGAffineTransformIdentity,
                                       self.bounds.size.width,   // espai entre patrons (X)
                                       2,   // espai entre patrons (Y)
                                       kCGPatternTilingConstantSpacing,
                                       true,
                                       &callbacks);

and this is the pattern code:

void MyDrawColoredPattern2 (void *info, CGContextRef context) {

    UIColor* __autoreleasing blauClar = [UIColor colorWithRed: 0.65 green: 0.65 blue: 0.65 alpha: 1];
    UIColor* __autoreleasing blauFosc = [UIColor colorWithRed: 0.106 green: 0.345 blue:0.486 alpha:1];     
    CGColorRef dotColor = blauFosc.CGColor;
    CGColorRef shadowColor = blauClar.CGColor;

    CGContextSetFillColorWithColor(context, dotColor);
    CGContextSetShadowWithColor(context, CGSizeMake(0, 1), 5, shadowColor);

    CGContextFillRect(context, CGRectMake(0, 0, 480, 1));
}

Previously I did a pattern which draw two hexagons inside a 24+24 square. It looked more complicated that the code above but it takes only 0.15 seconds to get drawn.

Am I doing something wrong here? My knowledge about quartz drawing is not really that big and I would appreciate some inputs. Thanks in advance!

  • 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-04T22:55:36+00:00Added an answer on June 4, 2026 at 10:55 pm

    I hate to answer myself, but after some trial and error I found that changing the pattern code to the following, does the trick:

    UIColor *__autoreleasing tileColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"pattern6-65.png"]];
    
    CGColorRef tileCGColor = [tileColor CGColor];
    CGColorSpaceRef colorSpace = CGColorGetColorSpace(tileCGColor);
    CGContextSetFillColorSpace(context, colorSpace);
    
    if (CGColorSpaceGetModel(colorSpace) == kCGColorSpaceModelPattern)
    {
        CGFloat alpha = 1.0f;
        CGContextSetFillPattern(context, CGColorGetPattern(tileCGColor), &alpha);
    }
    else
    {
        CGContextSetFillColor(context, CGColorGetComponents(tileCGColor));
    }
    
    CGContextFillRect(context, CGRectMake(0, 0, 10, 10));
    

    What it does is to fill the screen with a pattern generated with a very small png. So I had to draw the png with photoshop and then add it to the project. The bigger the png the faster it gets, but the more difficult is it to draw in photoshop.

    The call for the pattern must be modiffied to fit the size of the png (10 pixels here):

    CGPatternRef pattern = CGPatternCreate(NULL,
                                                 rect,//superficie que ha de cobrir CGRectMake(0, 0,self.bounds.size.width,8),
                                               CGAffineTransformIdentity,
                                               10,   // espai entre patrons (X) self.bounds.size.width
                                               10,   // espai entre patrons (Y)
                                               kCGPatternTilingConstantSpacing,
                                               true,
                                               &callbacks);
    

    using this 10px png, the whole drawing time has drop to 0.18 seconds (gradient background plus pattern).

    I hope it helps somebody with the same problem.

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

Sidebar

Related Questions

I have a grouped tableview which I set its background like this in viewDidload;
My tableview has 4 cells, and each cells has one different picture as background.
My tableView consists of 5-10 cells, each of which contains a scrollview of images.
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { if(section != 0) { UIView *view = [[[UIView
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { MaSystemGuiAppDelegate *appDelegate = (MaSystemGuiAppDelegate *)[[UIApplication sharedApplication] delegate]; appDelegate.deneme
I have a tableview that occupies only the bottom third of my view. I
I have a tableView which has cells with phone numbers. The app is not
I have a tableView:didSelectRowAtIndexPath: where I create a ViewController-Instance each time an item is
tableview .BackgroundColor:[UIColor colorWithRed:1 green:1 blue:0.75 alpha:1]; This is my code for changing background color
My tableview is in this user interface: But when I start search the view

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.