创建自定义UIScrollView滚动条

时间:2012-06-14 07:15:04

标签: iphone objective-c ios xcode

好的,我一直在互联网上试图找到答案,我正在尝试创建一个自定义的UIScrollView滚动条。

这是指向滚动条图片的链接

http://postimage.org/image/cg2jvde9z/

http://postimage.org/image/ko0mp3kdj/ (那个白盒子只供我测试滚动视图)

我已经让滚动条工作了,虽然我需要帮助确定每次滚动滚动时滚动视图应移动多少像素

这是一些代码

-(IBAction)scroller_bar:(id)sender withEvent:(UIEvent *)event{    
UIButton *button_sent = (UIButton *)sender;

UITouch *touch = [[event touchesForView:button_sent] anyObject];

CGPoint previousLocation = [touch previousLocationInView:button_sent];
CGPoint location = [touch locationInView:button_sent];
CGFloat delta_x = location.x - previousLocation.x;
float left_side = button_sent.center.x + delta_x;
float right_side = button_sent.center.x + delta_x;
if (right_side > button_sent.center.x) {
    scroll_right = YES;
}
else{
    scroll_right = NO;
}
if (left_side <= 13 + 50.5 || right_side >= 307 - 50.5) {

}
else{
    button_sent.center = CGPointMake(button_sent.center.x + delta_x,
                                     button_sent.center.y);

    if (scroll_right) {

    [selection_scroll setContentOffset:CGPointMake(selection_scroll.contentOffset.x - (Help HERE!), selection_scroll.contentOffset.y) animated:YES];
    }
    else{

        [selection_scroll setContentOffset:CGPointMake(selection_scroll.contentOffset.x + (Help HERE!), selection_scroll.contentOffset.y) animated:YES];


    }
}

}

在上面的代码中,您应该看到'(帮助在这里!)',

这就是我想弄清楚我应该移动滚动视图的像素数。这是一个令人困惑的问题,希望你理解。

谢谢:)

1 个答案:

答案 0 :(得分:1)

我不知道APPLE是否会批准这个,但下面写的代码可以改变scollView的滚动图像

for (UIImageView *img in yourscrollView.subviews) { 
    [img setImage:[UIImage imageNamed:@"your custom scroller image"]];
}