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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:35:02+00:00 2026-05-30T16:35:02+00:00

I want to create a subclass of UITableView or UIScrollView that will have some

  • 0

I want to create a subclass of UITableView or UIScrollView that will have some shading at the top when the content offset is > 0 to indicate that the content is scrollable. (See image attached)
enter image description here

The way I’m implementing it right now is using the UIViewController that is the delegate of the tableView. I simply have a GradientView on top of the tableView, and I intercept scrollViewDidScroll: to animate the visibility of that top gradient.

My problem with this implementation is that it’s not “clean”. I want my UIViewControllers to take care of logic, and not to deal with applying gradients and stuff. I wish I could just drop a subclass of UITableView that will do that for me.

The challenge for me is that I can’t figure out how the tableView could add to itself a fixed content on top of the scrollable content.

Another question is what method/s of UIScrollView should I override to intercept the scrolling event. Obviously I don’t want the tableView to be the delegate of itself…

Any ideas?

Thanks!

  • 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-30T16:35:03+00:00Added an answer on May 30, 2026 at 4:35 pm

    Ok, so I found the solution on Apple’s WWDC 2011 Session 104 video – Advanced Scroll View Techniques.

    There is a whole section in this video about “Stationary Views” inside a scroll view.
    According to Apple, the way to go here is to override layoutSubviews and put there all the code to position whatever you want – wherever you want.

    I tried it and it’s actually pretty easy and it’s working as expected.

    So for example if I would like a shadowed header on top of the table when the content is being scrolled, this is the code I should write:

    -(void) layoutSubviews
    {
        [super layoutSubviews];
        [self positionTopShadow];
    }
    
    -(void) positionTopShadow
    {
        CGFloat yOffset = self.contentOffset.y;
        // I'm doing some limiting so that the maximum height of the shadow view will be 40 pixels
        yOffset = MIN(yOffset, 40);
        yOffset = MAX(0, yOffset);
    
        CGRect frame = self.topShadowView.frame;
        // The origin should be exactly like the content offset so it would look like
        // the shadow is at the top of the table (when it's actually just part of the content) 
        frame.origin = CGPointMake(0, self.contentOffset.y);
        frame.size.height = yOffset;
        frame.size.width = self.frame.size.width;
        self.topShadowView.frame = frame;
    
        if (self.topShadowView.superview == nil)
        {
            [self addSubview:self.topShadowView];
        }
        [self bringSubviewToFront:self.topShadowView];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create an NSOutlineView subclass where some of the entries look like
I want to create a simple http proxy server that does some very basic
I want to create my own control that will consist of several UILabels and
I want to create a Category class that may or may not have a
We want to create a subclass of Canvas that only allows children of a
I have a dictionary that I read from a plist. I want to create
I really want to create a subclass of FutureTask that has a default no-arg
I want to create a method in superclass of test-class that stubs some commonly
Basically I want to re-style UITableView(Controller). Each cell will have a picture as a
I want to subclass a UITableView as I want to create a reusable table

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.