iOS自定义PageControl

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

内容简介:我们经常会用到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


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

查看所有标签

猜你喜欢:

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

Spark

Spark

Bill Chambers、Matei Zaharia / O′Reilly / 2017-10-31 / GBP 39.99

Learn how to use, deploy, and maintain Apache Spark with this comprehensive guide, written by the creators of the open-source cluster-computing framework. With an emphasis on improvements and new feat......一起来看看 《Spark》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码