UIPageControl使用

1.修改大小,创建一个类,继承UIPageControl,重写setCurrentPage方法,可设置圆点大小

- (void) setCurrentPage:(NSInteger)page {
      [super setCurrentPage:page];
      for (NSUInteger subviewIndex = 0; subviewIndex < [self.subviews count]; subviewIndex++) {
           UIImageView* subview = [self.subviews objectAtIndex:subviewIndex];
           CGSize size;
           size.height = 10;
           size.width = 10;
          [subview setFrame:CGRectMake(subview.frame.origin.x,subview.frame.origin.y,size.width,size.height)];
     }
}

2.如果只改变当前选中的点的大小,前面加个判断就可以了:

- (void) setCurrentPage:(NSInteger)page {
      [super setCurrentPage:page];
      for (NSUInteger subviewIndex = 0; subviewIndex < [self.subviews count]; subviewIndex++) {
          if (subviewIndex == page){
              UIImageView* subview = [self.subviews objectAtIndex:subviewIndex];
              CGSize size;
              size.height = 10;
              size.width = 10;
              [subview setFrame:CGRectMake(subview.frame.origin.x,subview.frame.origin.y,size.width,size.height)];
           }
       }
}

3.将点显示成图片的方法

[pageController setValue:[UIImage imageNamed:@"BluePoint.png"] forKeyPath:@"_currentPageImage"];
[pageController setValue:[UIImage imageNamed:@"black"] forKeyPath:@"_pageImage"];

4.设置点的颜色的方法

pageController.pageIndicatorTintColor = [UIColor blackColor];
pageController.currentPageIndicatorTintColor = [UIColor redColor];

你可能感兴趣的:(UIPageControl使用)