iOS自定义PageControl

栏目: IOS · 发布时间: 6年前

内容简介:我们经常会用到PageControl,但是系统的PageControl只有一种样式,不支持多样化,这里简单介绍一个简单的自定义PageControl.主要功能:实现:

自定义PageControl

我们经常会用到PageControl,但是系统的PageControl只有一种样式,不支持多样化,这里简单介绍一个简单的自定义PageControl.

主要功能:

  1. 可以自定义间隙

  2. 可以自定义高度

  3. 可以自定义选中点的宽度

  4. 每个点有点击事件

  5. 可以自定义选中和非选中的图片

  6. 可以设置居左、居中、居右样式

  7. 支持长条形状

实现:

将自定义PageControl类拖到项目中,并导入头文件.

//创建pageControl
XHPageControl  *_pageControl = [[XHPageControl alloc] initWithFrame:CGRectMake(0, 300,[UIScreen mainScreen].bounds.size.width, 30)];
//设置点的总个数
_pageControl.numberOfPages = 7;
//设置非选中点的宽度是高度的倍数(设置长条形状)
_pageControl.otherMultiple = 2;
//设置选中点的宽度是高度的倍数(设置长条形状)
_pageControl.currentMultiple = 4;
//设置样式.默认居中显示
_pageControl.type = PageControlLeft;
//非选中点的颜色  
_pageControl.otherColor=[UIColor grayColor];
//选中点的颜色  
_pageControl.currentColor=[UIColor orangeColor];
//代理    
_pageControl.delegate = self;
//标记    
_pageControl.tag = 902;

[self.view addSubview:_pageControl];

代理实现:

#pragma mark - 代理
-(void)xh_PageControlClick:(XHPageControl*)pageControl index:(NSInteger)clickIndex{

    NSLog(@"%ld",clickIndex);
    if(pageControl.tag == 902){
        CGPoint position = CGPointMake([UIScreen mainScreen].bounds.size.width * clickIndex, 0);
        [_scrollView2 setContentOffset:position animated:YES];
    }
}

代码demo: XHPageControl-Demo


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Algorithms of the Intelligent Web

Algorithms of the Intelligent Web

Haralambos Marmanis、Dmitry Babenko / Manning Publications / 2009-7-8 / GBP 28.99

Web 2.0 applications provide a rich user experience, but the parts you can't see are just as important-and impressive. They use powerful techniques to process information intelligently and offer featu......一起来看看 《Algorithms of the Intelligent Web》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具