Change width and colour of scroll bar in UITableView, iphone

chatur picture chatur · Nov 2, 2011 · Viewed 22.9k times · Source

I could only find if one wants to display scroll bar or not using

tableView.showsVerticalScrollIndicator = YES/NO;

but how can I customize the scroll bar for colour, width and if possible other features?

Any help will be greatly appreciated.

EDIT:

I got this idea from code snippets where one must find Google logo in MKMapKit and relocate it somewhere so that it remains visible. by following method one can set custom image to scroll bar of UItbaleview. But I found nothing on changing size of scroll bar.

-(void) ViewDidLoad
{
UIImageView *testView = [self.tableView.subviews objectAtIndex:1];
    UIImage *Img = [UIImage imageNamed:@"image.png"];
    [testView setImage:Img];
}

EDIT: As suggested by Nekto you can use following to change width.

CGRect frame = testView.frame; 
frame.size.width = 10; //set any value you want.
testView.frame = frame;

Answer

Nekto picture Nekto · Nov 2, 2011

You can set only style of scroll indicators:

The style of the scroll indicators.

@property(nonatomic) UIScrollViewIndicatorStyle indicatorStyle

Styles:

Scroll Indicator Style The style of the scroll indicators. You use these constants to set the value of the indicatorStyle style.

typedef enum {
    UIScrollViewIndicatorStyleDefault,
    UIScrollViewIndicatorStyleBlack,
    UIScrollViewIndicatorStyleWhite
} UIScrollViewIndicatorStyle;

For example:

tableView.indicatorStyle = UIScrollViewIndicatorStyleBlack;