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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:26:40+00:00 2026-06-12T20:26:40+00:00

I am completely new to implementing custom drawRect method (and Core Graphics) but am

  • 0

I am completely new to implementing custom drawRect method (and Core Graphics) but am doing so to improve the scrolling performance for my UITableView. Please do let me know if I am doing anything stupid.

In my cell, I have a UIImage and over the bottom part of it I would like to print the caption of the image. However, in order for the caption text to show up clearly regardless of the image , I would like to have a black rectangle with opacity of ~75% on top of the UIImage and below the caption text.

I tried the following

[self.picture drawAtPoint:point];

[[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.75] setFill];
UIRectFill(CGRectMake(rect));

but that resulting fill actually eat into the UIImage (excuse my poor description sorry) and the part showing below the slightly transparent fill is the background of my UITableView…

I guess I could have made another image for the rectangle and then draw it on top of the self.picture but I am wondering whether this is an easier way to use UIRectFill to achieve this instead…

as mentioned, I am completely new to Core Graphics so any hints would be much appreciated. thanks in advance!


Also, I have a second question… the dimension (in pixel) of the image downloaded is twice that of the rect (in points) that it will fit in, to account for retina display. However, it is now currently going over that rect, even on an iPhone4 device… How can I fix that (including for pre-iPhone4 devices too?)

  • 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-12T20:26:41+00:00Added an answer on June 12, 2026 at 8:26 pm

    I don’t do much custom drawRect stuff, so I’ll defer that portion of the question to someone else, but usually tableview performance issues are solved much more easily by moving the expensive calculations into a background queue and then asynchronously updating cell from the main queue when that background operation is done. Thus, something like:

    First, define an operation queue property for the tableview:

    @property (nonatomic, strong) NSOperationQueue *queue;
    

    Then in viewDidLoad, initialize this:

    self.queue = [[NSOperationQueue alloc] init];
    self.queue.maxConcurrentOperationQueue = 4;
    

    And then in cellForRowAtIndexPath, you could then:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"MyCellIdentifier";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
        // Do the quick, computationally inexpensive stuff first, stuff here.
        // Examples might include setting the labels adding/setting various controls
        // using any images that you might already have cached, clearing any of the
        // image stuff you might be recalculating in the background queue in case you're
        // dealing with a dequeued cell, etc.
    
        // Now send the slower stuff to the background queue.
    
        [self.queue addOperationWithBlock:^{
    
            // Do the slower stuff (like complex image processing) here.
            // If you're doing caching, update the cache here, too.
    
            // When done with the slow stuff, send the UI update back
            // to the main queue...
    
            [[NSOperationQueue mainQueue] addOperationWithBlock:^{
    
                // see if the cell is still visible, and if so ...
    
                UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                if (cell)
                {
                    // now update the UI back in the main queue
                }
            }];
    
        }];
    
        return cell;
    }
    

    You can optimize this further by making sure that you cache the results of your computationally-expensive stuff into something like a NSCache, and perhaps to Documents or elsewhere as well, thus as you can optimize how often that complex stuff has to be done and really optimize the UI.

    And, by the way, when you do that, you can now just have your UILabel (with backgroundColor using that UIColor for black with 0.75 alpha) on top of the the UIImageView, and iOS takes care of it for you. As easy as it gets.

    On the final question about image resolution, you can either:

    • use the view’s contentScaleFactor to figure out whether you’re dealing with retina or not and resize the thumbnail image accordingly; or
    • just use the imageview’s contentMode of UIViewContentModeScaleAspectFill which will make sure that your thumbnail images are rendered correctly regardless … if you’re using small thumbnail images (even 2x images), the performance is generally fine.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to the UITableView and noticed that w/out implementing a method the UITableViewCell
Completely new to most of this stuff, but basically Im playing around with the
I'm completely new to javascript, but I'm trying to create a beta form for
I am completely new to the world of PostgreSQL, please be patient with me.
Im implementing a video playback in android im completely new to android, and this
Completely new to asp.net mvc... completely new to web apps so bear with me...
Completely new to java and I have been playing around with regex in a
I am completely new to HTML5 and have been reading about it for the
I am completely new to Jena/TDB. All I want to do is to load
I am Completely new to Objective C and Cocoa programming. Why does NSApplicationMain not

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.