《竖着显示的“UIPageControl”》
竖着显示的“UIPageControl”,其实是自己封装的一个UIButton
原理:根据传入的page的个数利用for循环创建UIButton,默认的都是灰色!再创建一个红色UILabel,滑动scroll的时候,让UILabel跟着button的坐标走
//pageControl
- (void)customButton:(NSInteger)btnCount {
NSIntegeri =0;
NSMutableArray *arr = [NSMutableArray arrayWithCapacity:0];
_arrBtn = [[NSMutableArray alloc] initWithCapacity:0];
for (; i<btnCount; i++) {
UIButton*button= [UIButton buttonWithType:UIButtonTypeCustom];
button.frame=CGRectMake(0, i*15,10,10);
button.clipsToBounds=YES;
button.layer.cornerRadius=5;
button.tag=1001+i;
button.backgroundColor= [UIColor grayColor];
[_viewPage addSubview:button];
[arr addObject:button];
}
UILabel*label = [[UILabel alloc]initWithFrame:CGRectMake(0,0,10,10)];
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*)[_viewPageviewWithTag:3000];
label.frame=CGRectMake(0, tag*15,10,10);
}