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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:53:50+00:00 2026-06-16T11:53:50+00:00

I have a UITableViewCell Subclass that I add an overlay gradient like this: -(id)initWithCoder:(NSCoder

  • 0

I have a UITableViewCell Subclass that I add an overlay gradient like this:

-(id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {

        // add a layer that overlays the cell adding a subtle gradient effect
        _gradientLayer = [CAGradientLayer layer];
        _gradientLayer.frame = self.bounds;
        _gradientLayer.colors = @[(id)[[UIColor colorWithWhite:1.0f alpha:0.2f] CGColor],
                                  (id)[[UIColor colorWithWhite:1.0f alpha:0.1f] CGColor],
                                  (id)[[UIColor clearColor] CGColor],
                                  (id)[[UIColor colorWithWhite:0.0f alpha:0.1f] CGColor]];
        _gradientLayer.locations = @[@0.00f, @0.01f, @0.95f, @1.00f];
        [self.layer insertSublayer:_gradientLayer atIndex:0];
    }
    return self;
}
-(void) layoutSubviews {
    [super layoutSubviews];
    // ensure the gradient layers occupies the full bounds
    _gradientLayer.frame = self.contentView.frame;
}

The problem is, the gradient doesn’t cover the space my Accessory View takes up:
enter image description here

and you can also see in the top left corner that it doesn’t curve either.

How can I get the gradient to take up the full cell space?

EDIT—–

As suggested below, i’ve added:

+(Class)layerClass
{
    return [CAGradientLayer class];
}

and changed the cell’s init method to:

-(id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        _gradientLayer = (CAGradientLayer*)self.layer;
        _gradientLayer.colors = @[(id)[[UIColor colorWithWhite:1.0f alpha:0.2f] CGColor],
                                  (id)[[UIColor colorWithWhite:1.0f alpha:0.1f] CGColor],
                                  (id)[[UIColor clearColor] CGColor],
                                  (id)[[UIColor colorWithWhite:0.0f alpha:0.1f] CGColor]];
        _gradientLayer.locations = @[@0.00f, @0.01f, @0.95f, @1.00f];
    }
    return self;
}

However, now the gradients show like this:
enter image description here

EDIT 2 ———
Tarks suggestion below, using a gradient in a UIView then assigning to the cell’s background gives this result!
enter image description 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-16T11:53:51+00:00Added an answer on June 16, 2026 at 11:53 am

    This might work as solution in your case:

    Use a asset/dynamicaly created gradient-Image and use [UIColor colorWithPatternImage:gradientImage] for setting the backgroundColor property of your cell.

    If you want to use your layer solution, you have to set a mask to your gradientlayer, but the shape of the mask depends on the position of the cell in the section and so on…

    You Should avoid using transparency/alpha in your gradient, at least in your example you do not need it.

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

Sidebar

Related Questions

Similar to this question I have a custom subclass of UITableViewCell that has a
I am working in a class that is a subclass of UITableViewCell and have
I have a UITableView subclass and a UITableViewCell subclass that I'm using for cells.
I created a subclass of UITableViewCell and added two identical UIView s that have
I have an entity that represents a Person and a UITableViewCell subclass that displays
I have a subclass of UITableViewCell that I create for a UITableView. Let's say
So in a UITableViewCell subclass this works great: - (void)awakeFromNib { [super awakeFromNib]; UIImageView
I have created a subclass of a UITableViewCell that I am using with some
So I have a UITableViewCell subclass that needs to know whether the UITableView is
I have a UITableViewCell subclass with backgroundView set to my own UIView object. This

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.