《豎著顯示的“UIPageControl”》
?豎著顯示的“UIPageControl”,其實是自己封裝的一個UIButton?
原理:根據(jù)傳入的page的個數(shù)利用for循環(huán)創(chuàng)建UIButton乐严,默認的都是灰色捣作!再創(chuàng)建一個紅色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);
}