2016-01-08 214 views
0

我想在滾動視圖中沿滾動條移動UIImageview。我試過DidScroll代表沿滾動條在滾動視圖中移動圖像

- (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像素

+0

什麼是您爲scrollview設置的contentOffset? – jay

回答

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]]; 
} 
+0

兄弟,我已經嘗試過這個鏈接,但沒有成功,它只是改變圖像的顏色,也不移動圖像,我想移動圖像像滾動條 – zkn