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

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

时间:2016-07-30 00:20:56      阅读:178      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!