Make vertical scrollbar always visible in UIScrollView

Download : https://github.com/jaredsinclair/JTSScrollIndicator

JTSScrollIndicator.m

Add the following statements in the method initWithScrollView:

  • [_scrollView setShowsHorizontalScrollIndicator:NO];
  • [_scrollView setShowsVerticalScrollIndicator:NO];

Comment all the statements in the method hide:

JTSScrollIndicator.h

Added the following method declarations

  • – (void)show:(BOOL)animated;
  • + (BOOL)indicatorShouldBeVisibleForScrollView:(UIScrollView *)scrollView;

ViewController.h

#import “JTSScrollIndicator.h”
@property (strong, nonatomic) JTSScrollIndicator *indicator;

ViewController.m

- (void)viewDidLoad {
[super viewDidLoad];
self.indicator = [[JTSScrollIndicator alloc] initWithScrollView:scrollview];
self.indicator.backgroundColor = [UIColor colorWithRed:5.0/255.0 green:127.0/255.0 blue:231.0/255.0 alpha:1.0];
}

- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
scrollview.contentOffset = CGPointMake(0.0, 1.0);
[self.indicator show:YES];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
[self.indicator scrollViewDidScroll:scrollView];
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
[self.indicator scrollViewDidEndDragging:scrollView willDecelerate:decelerate];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
[self.indicator scrollViewDidEndDecelerating:scrollView];
}

- (void)scrollViewWillScrollToTop:(UIScrollView *)scrollView {
[self.indicator scrollViewWillScrollToTop:scrollView];
}

- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView {
[self.indicator scrollViewDidScrollToTop:scrollView];
}

Advertisements

Objective-C – How to use member variables in the categories.

.h

@interface UIView (ObjectTagAdditions)
@property (nonatomic, retain) id objectTag;
@end

.m

#import <objc/runtime.h>
static char const * const ObjectTagKey = "ObjectTag";

@implementation UIView (ObjectTagAdditions)
@dynamic objectTag;

- (id)objectTag {
    return objc_getAssociatedObject(self, &ObjectTagKey);
}

- (void)setObjectTag:(id)newObjectTag {
    objc_setAssociatedObject(self, &ObjectTagKey, newObjectTag, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

Cited from : http://oleb.net/blog/2011/05/faking-ivars-in-objc-categories-with-associative-references/