美文网首页
iOS UIPageControl的操作,设置圆点大小,显示图片

iOS UIPageControl的操作,设置圆点大小,显示图片

作者: 清蘂翅膀的技术 | 来源:发表于2017-06-20 18:30 被阅读0次

    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.将点显示成图片的方法

    [pageCon setValue:[UIImage imageNamed:@"BluePoint.png"] forKeyPath:@"_currentPageImage"];

    [pageCon setValue:[UIImage imageNamed:@"black"] forKeyPath:@"_pageImage"];

    4.设置点的颜色的方法

    pageCon.pageIndicatorTintColor = [UIColor blackColor];

    pageCon.currentPageIndicatorTintColor = [UIColor redColor];

    相关文章

      网友评论

          本文标题:iOS UIPageControl的操作,设置圆点大小,显示图片

          本文链接:https://www.haomeiwen.com/subject/ixjaqxtx.html