UIScrollview一直显示滚动条,使用UIImageView自定义滚动条

UIScrollview一直显示滚动条,使用UIImageView自定义滚动条


@interface ViewController ()<UIScrollViewDelegate>

{

    UIScrollView *backScrollView;

    UIImageView *scrollIndexerImageView;

}

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    

    backScrollView = [[UIScrollView allocinitWithFrame:CGRectMake(1020200300)];

    backScrollView.backgroundColor = [UIColor greenColor];

    backScrollView.contentSize = CGSizeMake(200900);

    backScrollView.showsHorizontalScrollIndicator = NO;

    backScrollView.showsVerticalScrollIndicator = NO;

    backScrollView.delegate = self;

    

    [self.view addSubview:backScrollView];

    

    scrollIndexerImageView = [[UIImageView allocinitWithFrame:CGRectMake(backScrollView.frame.size.width-808,30)];

    scrollIndexerImageView.image = [UIImage imageNamed:@"teacherlist_select_scrollbar"];

    [backScrollView addSubview:scrollIndexerImageView];

    

}

 

-(void)scrollViewDidScroll:(UIScrollView *)scrollView

{

    float p = 0;

    p = scrollView.contentOffset.y/(scrollView.contentSize.height - scrollView.frame.size.height+(scrollIndexerImageView.frame.size.height-scrollIndexerImageView.frame.size.height*scrollView.frame.size.height/scrollView.contentSize.height));

    scrollIndexerImageView.frame = CGRectMake(backScrollView.frame.size.width-8,p*scrollView.contentSize.height,8,30);

 

    NSLog(@"y:%f",scrollView.contentOffset.y);

    NSLog(@"--:%f",scrollIndexerImageView.frame.origin.y);

}

原文地址:http://www.wahenzan.com/a/mdev/ios/2014/1215/350.html

你可能感兴趣的:(移动开发,iphone开发,uiscrollview,uiimageview,interface,uiimage)