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

  • Home
  • SEARCH
  • 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 6800403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:57:53+00:00 2026-05-26T18:57:53+00:00

I have a subclassed UIButton inside a subclassed UITableViewCell . The button is loaded

  • 0

I have a subclassed UIButton inside a subclassed UITableViewCell. The button is loaded from a nib.

I have an image I want to use as the image for the button. I would like to use CALayer for more control over animation. When the user taps the button, animation will occur. But, I can’t even get the image to show up.

QuartzCore is imported.

Code of my subclassed UIButton (always loaded from a nib):

-(void)awakeFromNib {
    [super awakeFromNib];
    self.clipsToBounds = NO;
    self.backgroundColor = [UIColor clearColor];
    self.opaque = NO;
    self.userInteractionEnabled = YES;
}

Code in the table view controller:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MyCustomCell *cell = (BLCustomCellCenter*)[tableView dequeueReusableCellWithIdentifier:@"customCellID"];
    if (cell == nil) {
        // ... cell is initialized
    }

    // configure the image for the button
    //
    // Note:  there is an outlet to the UIButton called 'customButton' 

    CALayer *imgLayer = [CALayer layer];
    imgLayer.bounds = CGRectMake(0, 0, cell.customButton.bounds.size.width, cell.customButton.bounds.size.height);
    imgLayer.position = CGPointMake(cell.customButton.bounds.size.width/2, cell.customButton.bounds.size.height/2);
     UIImage *img = [UIImage imageNamed:@"someImage"];
    imgLayer.contents = (id)[img CGImage];
    [cell.customButton.layer addSublayer:imgLayer];

    // ... configure subviews of 'customButton'

    return cell;
}

Any help very much appreciated, as always.

  • 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-26T18:57:54+00:00Added an answer on May 26, 2026 at 6:57 pm

    Figured it out, after hours of debugging. The thing (that perhaps I forgot to mention) was that the custom UITableViewCell was loaded from a nib. The subview I wanted to view was also loaded from a nib. So, it’s a nib within a nib.

    Per this wonderful article, overriding awakeAfterUsingCoder: inside the subview’s class did the trick. When loading the parent nib, the super’s initUsingCoder:is called on the subview which loads only a placeholder object.

    This ‘placeholder’ object was causing my problems as I was manipulating the placeholder instead of the actual object I wanted.

    Therefore, you have to load and initialize the subview’s objects from the nib, and you do this by overriding NSObject‘s awakeAfterUsingCoder:.

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

Sidebar

Related Questions

I have a custom button, subclassed from UIButton that is initialised as below (obviously
I have subclassed a UITableViewCell and within this class I want to get it's
I have a button that uses a stretchable PNG as the background image, like
I have created a custom UIView that I would like to use on multiple
I have subclassed Process like so: class EdgeRenderer(Process): def __init__(self,starter,*args,**kwargs): Process.__init__(self,*args,**kwargs) self.starter=starter Then I
I have subclassed UIView object inside a uiscrollview which displays a pdf page. I
I am looking to create a Custom UIButton (not subclass) progrmatically, I would like
I have created a custom UIButton (UIButton subclass) for my application. Within this button's
I have a custom-subclassed UITableViewCell which will include a few labels, to which I
I have a button that's created via a NIB file. I've derived a class

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.