Latest 0.1.3
Homepage https://github.com/modocache/MDCScrollBarLabel
License MIT
Platforms ios 5.0, requires ARC
Frameworks UIKit
Authors

An animated scroll bar to present extra information when scrolling on a UIScrollView.

Y’know, like the clock on Path.

MDCScrollBarLabel GIF

Usage

Basically, you have two options. You can:

  • Subclass MDCScrollBarViewController and set an MDCScrollBarLabel to its
    scrollBarLabel property.
  • Implement a UIViewController which is a UIScrollBarDelegate, then call the
    fade in/out logic for the label as you’d like.

See the example application for usage.

Subclassing MDCScrollBarViewController

#pragma mark - Creating the Scroll Bar Label

- (void)viewDidLoad {
    [super viewDidLoad];

    // Create a table view with a row height of 100.f
    CGSize size = self.view.frame.size;
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds
                                                  style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 100.f;
    [self.view addSubview:self.tableView];

    // Add a scroll bar label to the table view
    self.scrollBarLabel = [[MDCScrollBarLabel alloc] initWithScrollView:self.tableView];
    [self.tableView addSubview:self.scrollBarLabel];
}

#pragma mark - Updating the Date on the Scroll Bar Label

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    [super scrollViewDidScroll:scrollView];

    // Determine which row the scroll bar label is currently hovering over
    NSInteger rowNumber = CGRectGetMinY(self.scrollBarLabel.frame) / 100.f;

    // Update the date on the label using the model data for that row
    // (here we assume you have a model named `Event`)
    Event *event = self.events[rowNumber];
    self.scrollBarLabel.date = event.date;
}

Subclassing UIViewController <UIScrollViewDelegate>

#pragma mark - Show/Hide the Label Using UIScrollViewDelegate Callbacks

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    [self.scrollBarLabel adjustPositionForScrollView:scrollView];
    [self.scrollBarLabel setDisplayed:YES animated:YES afterDelay:0.0f];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    [self.scrollBarLabel setDisplayed:NO animated:YES afterDelay:self.scrollBarFadeDelay];
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView
                  willDecelerate:(BOOL)decelerate {
    if (!decelerate) {
        [self.scrollBarLabel setDisplayed:NO animated:YES afterDelay:self.scrollBarFadeDelay];
    }
}

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
    [self.scrollBarLabel setDisplayed:NO animated:YES afterDelay:self.scrollBarFadeDelay];
}

- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView {
    [self.scrollBarLabel setDisplayed:NO animated:YES afterDelay:self.scrollBarFadeDelay];
}

License

MIT license. See the LICENSE file for details.

Latest podspec

{
    "name": "MDCScrollBarLabel",
    "version": "0.1.3",
    "summary": "Like Path's timestamp scrollbar label.",
    "homepage": "https://github.com/modocache/MDCScrollBarLabel",
    "license": "MIT",
    "authors": {
        "modocache": "[email protected]"
    },
    "social_media_url": "https://twitter.com/modocache",
    "source": {
        "git": "https://github.com/modocache/MDCScrollBarLabel.git",
        "tag": "v0.1.3"
    },
    "source_files": "*.{h,m}",
    "resources": "Resources/Images/*.png",
    "requires_arc": true,
    "platforms": {
        "ios": "5.0"
    },
    "frameworks": "UIKit"
}

Pin It on Pinterest

Share This