在 iPhone 中,我将使用图像自定义 UITableView 的滚动条。但是我没有找到正确的方法。请帮我。提前致谢。
问问题
1783 次
1 回答
1
首先,您必须在 Interface Builder 中取消选中 showVerticalIndicatir 和 showHorizontallIndicatir。
然后在 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];
然后在 - (void)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];
于 2014-07-07T11:49:14.247 回答