竖着显示的“UIPageControl”

来源:互联网 发布:《梦里花落知多少》txt 编辑:程序博客网 时间:2024/04/29 09:09
竖着显示的“UIPageControl”

 竖着显示的“UIPageControl”,其实是自己封装的一个UIButton 

原理:根据传入的page的个数利用for循环创建UIButton,默认的都是灰色!再创建一个红色UILabel,滑动scroll的时候,让UILabel跟着button的坐标走

//pageControl

- (void)customButton:(NSInteger)btnCount {

    NSInteger i = 0;

    NSMutableArray *arr = [NSMutableArray arrayWithCapacity:0];

    _arrBtn = [[NSMutableArray allocinitWithCapacity:0];

    for (; i<btnCount; i++) {

        UIButton *button= [UIButtonbuttonWithType:UIButtonTypeCustom];

        button.frame = CGRectMake(0, i*151010);

        button.clipsToBounds = YES;

        button.layer.cornerRadius = 5;

        button.tag = 1001+i;

        button.backgroundColor = [UIColor grayColor];

        

        [_viewPage addSubview:button];

        [arr addObject:button];

    }

    UILabel *label = [[UILabel allocinitWithFrame:CGRectMake(00,1010)];

    label.backgroundColor = [UIColor redColor];

    label.clipsToBounds = YES;

    label.tag = 3000;

    label.layer.cornerRadius = 5;

    [_viewPage addSubview:label];

    self.arrBtn = arr;

} 

一般UIPageControl是配合UIScrollView显示的,但是既然UIPageControl是竖着显示;那么UIScrollView也是竖着滑动的,滑动Scroll的时候,PageControl跟着滑动

scroll代理方法

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {    

    NSInteger tag = scroll.contentOffset.y/scroll.frame.size.height;

    UILabel *label = (UILabel *)[_viewPage viewWithTag:3000];

    label.frame = CGRectMake(0, tag*151010);

}


0 0
原创粉丝点击