更改tableview中滚动条的颜色

时间:2016-01-04 07:13:52

标签: ios objective-c iphone uitableview scrollbar

我有一个viewcontroller。在里面我放置了一个tableview,其大小为320X295,位于我的viewcontroller的centre。所以我的桌面视图在我viewcontroller的中心位置是一半。

我的tableview未完全填充我的Viewcontroller 。现在我如何将scroll bar颜色更改为green color或某些RGB值。

这是我的代码:

    UIScrollView *scView = [[UIScrollView alloc] init];
    scView.frame = self.view.bounds; //scroll view occupies full parent views
    scView.contentSize = CGSizeMake(400, 400);
   // scView.backgroundColor = [UIColor lightGrayColor];
    scView.indicatorStyle = UIScrollViewIndicatorStyleBlack;

      scView.showsHorizontalScrollIndicator = NO;
    scView.showsVerticalScrollIndicator = YES;
    scView.scrollEnabled = YES;
    [self.containerTableView addSubview: scView];

ContainerTableView是我的桌面视图名称。

我需要将滚动条颜色更改为绿色。请帮助我如何实现。谢谢

2 个答案:

答案 0 :(得分:1)

您可以使用名为UIScrollView

indicatorStyle属性来实现此目的

使用以下任何一种

typedef enum {
    UIScrollViewIndicatorStyleDefault,
    UIScrollViewIndicatorStyleBlack,
    UIScrollViewIndicatorStyleWhite
} UIScrollViewIndicatorStyle;

你可以像这样使用这种风格。

tableView.indicatorStyle = UIScrollViewIndicatorStyleBlack;

这里是参考链接..

Change width and colour of scroll bar in UITableView, iphone

答案 1 :(得分:1)

1.添加UIScrollViewDelegate

@interface ViewController : UIViewController<UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate>
@end

<强> 2。在实现部分中添加scrollViewDidScroll

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
//get refrence of vertical indicator
UIImageView *verticalIndicator = ((UIImageView *)[scrollView.subviews objectAtIndex:(scrollView.subviews.count-1)]);
//set color to vertical indicator
[verticalIndicator setBackgroundColor:[UIColor redColor]]; // Your color

//get refrence of horizontal indicator
UIImageView *horizontalIndicator = ((UIImageView *)[scrollView.subviews objectAtIndex:(scrollView.subviews.count-2)]);
//set color to horizontal indicator
[horizontalIndicator setBackgroundColor:[UIColor blueColor]]; // Your color
}