Pad*_*van 4 iphone objective-c ios
有没有一种方法可以自定义UIScrollView中的滚动指示器(垂直或水平)。例如,更改其颜色或在scrollview中的位置。
小智 5
首先,您必须在Interface Builder中取消选中showVerticalIndicator和showHorizontallIndicator。
然后在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];
Run Code Online (Sandbox Code Playgroud)
然后在- (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];
Run Code Online (Sandbox Code Playgroud)
这对我有用。