【发布时间】:2012-07-20 06:58:46
【问题描述】:
在 iPhone 中,我将使用图像自定义 UITableView 的滚动条。 但是我没有找到正确的方法。 请帮我。 提前致谢。
【问题讨论】:
-
您的问题不清楚,请在您的问题中添加更多详细信息..
标签: iphone ios uitableview scrollbar customization
在 iPhone 中,我将使用图像自定义 UITableView 的滚动条。 但是我没有找到正确的方法。 请帮我。 提前致谢。
【问题讨论】:
标签: iphone ios uitableview scrollbar customization
首先,您必须在 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];
【讨论】: