Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change width and colour of scroll bar in UITableView, iphone

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;
like image 487
chatur Avatar asked Nov 02 '11 06:11

chatur


4 Answers

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; 
like image 160
Nekto Avatar answered Sep 30 '22 07:09

Nekto


You can change the scroll indicator color using:

tableView.indicatorStyle=UIScrollViewIndicatorStyleWhite; 

Hope this helps.

like image 38
Birju Avatar answered Sep 30 '22 07:09

Birju


You can add this great open source custom scrollbar to your project, its totally customisable: https://github.com/BasheerSience/BRScrollBar

like image 31
Basheer_CAD Avatar answered Sep 30 '22 07:09

Basheer_CAD


You can hide the original scroll bar and scroll using your custom scroll bar.

– (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated 

can be used to scroll content, just add your custom bar to the table.

like image 43
Manali Avatar answered Sep 30 '22 05:09

Manali