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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:30:10+00:00 2026-06-05T11:30:10+00:00

I am having a wicked time trying to get an image to show up

  • 0

I am having a wicked time trying to get an image to show up in a CALayer.contents. It seems rather straight forward but I cannot get the image to render no matter what I do. The CALayer renders fine as I can see its background color and corner radius, but the image will not load.

enter image description here

What you are seeing here is a CAGradientLayer subclass with a mask applied. The inner square is where I would like the image to show, and it is added as a sublayer of the CAGradientLayer subclass.

The code to set this up is pretty straightforward. In init:

self.imageLayer = [CALayer layer];
self.imageLayer.cornerRadius = kDefaultCornerRadius;
self.imageLayer.backgroundColor = [UIColor darkGrayColor].CGColor;
[self addSublayer:self.imageLayer];

Then later on, I set the image:

- (void)setImage:(UIImage *)image {
    self.imageLayer.contents = (id)image.CGImage;
    [self.imageLayer setNeedsDisplay];
}

Finally, within setFrame:

CGFloat imageSize = self.bounds.size.width - 2*kDefaultMargin;
[self.imageLayer setBounds:CGRectMake(0.0, 0.0, imageSize, imageSize)];
[self.imageLayer setPosition:CGPointMake(self.bounds.size.width/2.0f, kDefaultMargin + imageSize/2.0f)];
[self.imageLayer setNeedsDisplay];

Things I already know or have checked:

  1. The layer is obviously added correctly evident by it being visible.
  2. The image is added and works. [UIImage imageNamed:@"info.png"] is being used elsewhere in the code and actually shows and image. It is 16×16 at 1x and 32×32 at 2x
  3. The code is being called in the correct logical order: init, setImage:, setFrame;

What is going on here?

  • 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-05T11:30:11+00:00Added an answer on June 5, 2026 at 11:30 am

    Remove this line:

    [self.imageLayer setNeedsDisplay];
    

    -setNeedsDisplay tells a layer that it needs to redraw its contents. Since you already provided the content for the layer, you don’t want CA to discard that content and ask for a replacement.

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

Sidebar

Related Questions

I'm trying to write a software in JavaScript, but I'm having hard time trying
Having val hm: HashMap[org.joda.time.DateTime, MyType] I am trying to get the first and the
Having a hard time with labels on a ggplot2 plot. Here's a similar plot
Having just added a new button in my web application, I get an error
Having trouble with an .htaccess file on WAMP. Works on the live server, but
Having read the documentation for VPython and GTK threading , it seems to me
Having some trouble w/ IE7. IE8, Chrome, Firefox all work fine, but IE7 won't
I'm having a hard time testing our Wicket application using Selenium because of the
Having a duh moment trying to implement a new content page Here's the structure
Having the following domain class: class Message{ } Want to get all messages with

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.