2012-07-20 68 views
2

在iPhone中,我将使用图像定制UITableView的滚动条。 但我没有找到正确的方法。 请帮帮我。 在此先感谢。iOS在UITableView中定制滚动条

+0

你所要求的不明确增加更多的细节,你的问题.. – Leena 2012-07-20 10:21:19

回答

1

首先,您必须在Interface Builder中取消选中showVerticalIndicatir和showHorizo​​ntallIndicatir。

然后在viewDidLoad中添加梅索德:

[super viewDidLoad]; 
    self.scrollViewBarImgView = [[UIImageView alloc] init]; 
    UIImage *imgBar = [UIImage imageNamed:@"scroller.png"]; 
    [self.scrollViewBarImgView setImage:imgBar]; 
    CGRect frame = scrollViewBarImgView.frame; 
    frame.size.width = 8; 
    frame.size.height = 60; 
    frame.origin.x = 312; 
    frame.origin.y = 0; 
    [self.scrollViewBarImgView setFrame:frame]; 

[self.tableView addSubview:scrollViewBarImgView]; 

然后在 - (空)scrollViewDidScroll梅索德:

CGPoint offset = scrollView.contentOffset; 
CGRect frame = self.scrollViewBarImgView.frame 
float fact = (cellHeight*numberOfRow+ indicatorBarHeight)/tableViewHeight; 
frame.origin.y = offset.y + (offset.y/fact); 
[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:0.1]; 
[self.scrollViewBarImgView setFrame:frame]; 
[UIView commitAnimations]; 
+0

我我对这个解决方案进行了一些修改。例如,动画部分是不必要的;实际上,它在滚动中创造了一些滞后。 谢谢@SOUA Hamza。 – Leandro 2016-02-22 15:35:56