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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:32:55+00:00 2026-05-27T19:32:55+00:00

I have a UITableViewCell with a UIImage that I’m drawing. As I scroll, I

  • 0

I have a UITableViewCell with a UIImage that I’m drawing. As I scroll, I get a ton of sublayers getting added which makes performance really jerky. How can I make sure my CALayer only gets added once?

- (void) drawContentView:(CGRect)rect {
    CGContextRef context = UIGraphicsGetCurrentContext();
    [[UIColor whiteColor] set];
    CGContextFillRect(context, rect);

    NSString* caption = [NSString stringWithFormat:@"%@",[info objectForKey:@"caption"]];
    NSString* text = [info stringForKey:@"text"];

    CGFloat widthr = self.frame.size.width - 70;

    [[UIColor grayColor] set];
    [text drawInRect:CGRectMake(63.0, 25.0, widthr, 20.0) withFont:system14 lineBreakMode:UILineBreakModeTailTruncation];

    if (self.image) {
        UIImage *imageToDisplay;
        imageToDisplay = self.image;
        imageToDisplay = [self imageWithImage:imageToDisplay scaledToSize:CGSizeMake(imageToDisplay.size.width / 1.5, imageToDisplay.size.height / 1.5)];
        CGFloat width;
        CGFloat height;
        CGRect r;
        if (imageToDisplay.size.width < 310 && imageToDisplay.size.height > 290) {
            imageToDisplay = [self imageByCropping:imageToDisplay toRect:CGRectMake(0, 20, imageToDisplay.size.width, 270)];

        }
        else if (imageToDisplay.size.width > 310 && imageToDisplay.size.height < 20) {
            imageToDisplay = [self imageByCropping:imageToDisplay toRect:CGRectMake(30, 0, 290, imageToDisplay.size.height)];
        }
        else {
            if (!) {
                imageToDisplay = [self imageByCropping:imageToDisplay toRect:CGRectMake(30, 0, 290, 230)];
            }
            else {
            imageToDisplay = [self imageByCropping:imageToDisplay toRect:CGRectMake(30, 0, 290, 270)];
            }
        }

        width = imageToDisplay.size.width;
        height = imageToDisplay.size.height;
        r = CGRectMake(5.0, 5.0, width, height);

        //[imageToDisplay drawInRect:r];

        CALayer *sublayer = [CALayer layer];
        sublayer.contents = (id)imageToDisplay.CGImage;
        sublayer.shadowOffset = CGSizeMake(0, 3);
        sublayer.shadowRadius = 5.0;
        sublayer.shadowColor = [UIColor blackColor].CGColor;
        sublayer.shadowOpacity = 0.8;
        sublayer.frame = CGRectMake(5.0, 5.0, imageToDisplay.size.width, imageToDisplay.size.height);
        [self.layer addSublayer:sublayer];

        //Experimental shadow stuff with images
        /*CALayer *layer = [CALayer layer];
        layer = [CALayer layer];
        layer.bounds = CGRectMake(5.0, 5.0, imageToDisplay.size.width, imageToDisplay.size.height);
        layer.position = CGPointMake(150, 140);
        layer.contents = (id)imageToDisplay.CGImage;    

        layer.shadowOffset = CGSizeMake(0, 2);
        layer.shadowOpacity = 0.70;

        [self.layer addSublayer:layer];

        [self bezierPathWithCurvedShadowForRect:layer.bounds];*/

        [[UIColor blackColor] set];
        ;
    }
}
  • 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-05-27T19:32:56+00:00Added an answer on May 27, 2026 at 7:32 pm

    drawContentView: is not the right method from which to call addSublayer:. You should add that layer at the point when you construct your object with an image, or when you set an image on an existing object. Alternatively, you can draw the image yourself in the drawContentView:, but it is probably not going to be as fast.

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

Sidebar

Related Questions

I have UITableViewCell s that have an imageView that loads a UIImage from a
I have an UIImageView in my UITableViewCell which is not being displayed. I get
I created a UITableViewCell in Interface Builder which I have added a UIImageView and
I have created a UITableViewCell using UITableViewCellStyleValue1, which the Apple docs define as: A
I have a custom UITableViewCell which contains several UIButtons. Each button's frame position is
I have a custom UITableViewCell which has an image & and some text. When
I have subclassed a UITableViewCell and within this class I want to get it's
I have a grouped UITableView that contains several cells (just standard UITableViewCell s), all
I have a UITextView inside a UITableViewCell . It's working as expected except that
I know that if I have some images and subviews added in customized cell

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.