沿滚动条在ScrollView中移动图像

时间:2016-01-08 05:53:28

标签: ios uiimageview scrollbar scrollview frame

我想在scrollview中沿着滚动条移动UIImageview。我试过DidScroll Delegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    static NSInteger previousPage = 0;
    NSLog(@"scrolliview= %f",scrollView.contentOffset.x);

   [_img_moving setBackgroundColor:[UIColor greenColor]];
    _img_moving.frame = CGRectMake(
                                 scrollView.contentOffset.x,
                                 0, 320/2, 10);

}

uiimageview的框架没有改变。 注意:我的目标是制作宽度为10像素的绿色滚动条

1 个答案:

答案 0 :(得分:0)

请尝试以下代码,根据需要更改垂直和水平滚动条的颜色,更多详细解答请点击此链接:
 ios Changing UIScrollView scrollbar color to different colors

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    //get refrence of vertical indicator
    UIImageView *verticalIndicator = ((UIImageView *)[scrollView.subviews objectAtIndex:(scrollView.subviews.count-1)]);
    //set color to vertical indicator
    [verticalIndicator setBackgroundColor:[UIColor greenColor]];


    //get refrence of horizontal indicator
    UIImageView *horizontalIndicator = ((UIImageView *)[scrollView.subviews objectAtIndex:(scrollView.subviews.count-2)]);
    //set color to horizontal indicator
    [horizontalIndicator setBackgroundColor:[UIColor redColor]];
}