首页 > 其他 > 详细

(转)UIPageControl使亮点直接跳到点击dot上

时间:2016-07-30 00:18:14      阅读:204      评论:0      收藏:0      [点我收藏+]

     其实所谓的dot就是加在pageControl上的UIImageView,有两种状态,一种是正常态,一种是高亮状态,而这些dot默认的userInteractionEnabled = NO;

所以解决办法也很简单了,把每个dot循环出来,将其userInteractionEnabled设为YES,并加上UIButton,将button的tag标注出来,并给button绑定一个事件,这样点击每个button也能取到其tag,取到tag就取到了对应的UIImageView,然后将button的tag赋给pageControl.currentPage,这样目的就达到了。

 

pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(50, 430, 220, 30)];
    pageControl.center = CGPointMake(mainScreenWidth / 2, 430);
    pageControl.backgroundColor = [UIColor clearColor];
    pageControl.numberOfPages = 8;
    int i = 0;
    for (UIImageView *imgV in [pageControl subviews]) {
        
        imgV.userInteractionEnabled = YES;   //默认为NO
        UIButton *botButton = [UIButton buttonWithType:UIButtonTypeCustom];
        botButton.frame = imgV.bounds;
        botButton.tag = i;
        botButton.backgroundColor = [UIColor clearColor];
        [botButton addTarget:self action:@selector(tapBotAction:) forControlEvents:UIControlEventTouchUpInside];
        [imgV addSubview:botButton];
        i++;
    }
    //[pageControl.layer setCornerRadius:8];   //设置圆角
    [pageControl addTarget:self action:@selector(changePageNumber:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:pageControl];
}

- (void)tapBotAction:(id)sender{
    
    int index = [(UIButton *)sender tag];
    pageControl.currentPage = index;
    [catalogScrollView setContentOffset:CGPointMake(index * catalogSlideRemoving, 0) animated:YES]; //if animated is ‘NO‘ animat don‘t implement

}

 

(转)UIPageControl使亮点直接跳到点击dot上

原文:http://www.cnblogs.com/yurunfei2011/p/5719843.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!