您的位置:首页 > 产品设计 > UI/UE

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

2014-12-15 18:32 453 查看
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 alloc] initWithFrame:CGRectMake(10, 20, 200, 300)];

backScrollView.backgroundColor =
[UIColor greenColor];

backScrollView.contentSize = CGSizeMake(200, 900);

backScrollView.showsHorizontalScrollIndicator = NO;

backScrollView.showsVerticalScrollIndicator = NO;

backScrollView.delegate = self;

[self.view addSubview:backScrollView];

scrollIndexerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(backScrollView.frame.size.width-8, 0, 8,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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: