3
有沒有辦法在UIScrollView中自定義滾動指標(垂直或水平)。例如,在滾動視圖中更改它的顏色或位置。自定義滾動指標
有沒有辦法在UIScrollView中自定義滾動指標(垂直或水平)。例如,在滾動視圖中更改它的顏色或位置。自定義滾動指標
首先,您必須在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];
然後在- (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];
這是爲我工作。