码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-12-15 19:05:23      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:uiscrollview   uiimageview   interface   uiimage   

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

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

标签:uiscrollview   uiimageview   interface   uiimage   

原文地址:http://blog.csdn.net/gloryflow/article/details/41946535

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!