自定义滚动控件(Pagecontrol)
2024-10-14 13:17:50
//
// MyPageCorol.h
// lejiahui
//
// Created by iOS开发 on 16/4/10.
// Copyright © 2016年 zhongmingwuye. All rights reserved.
// #import <UIKit/UIKit.h> @interface MyPageCorol : UIView /** 当前页数 */
@property(nonatomic,assign) NSInteger correntPage; /** itmenSize */
@property(nonatomic,assign) CGSize itmeSize; + (MyPageCorol *)myPageControlWithSuperView:(UIView *)superView; - (void)setImage:(UIImage *)image andSelectImage:(UIImage *)slectImage totalNum:(NSInteger)totalNum; - (void)setColor:(UIColor *)color andSelectColor:(UIColor*)selectColor totalNum:(NSInteger)totalNum; @end //
// MyPageCorol.m
// lejiahui
//
// Created by iOS开发 on 16/4/10.
// Copyright © 2016年 zhongmingwuye. All rights reserved.
// #import "MyPageCorol.h" @interface MyPageCorol()
{
NSMutableArray * _pageItems;
UIColor * _selectedColor;
UIColor * _color; UIImage * _image;
UIImage * _selectedImage; BOOL _isImage; NSInteger _width;
NSInteger _height;
} @end @implementation MyPageCorol + (MyPageCorol *)myPageControlWithSuperView:(UIView *)superView{
MyPageCorol * pl = [[MyPageCorol alloc]init];
pl.frame = CGRectMake(, superView.frame.size.height-, superView.frame.size.width, );
pl.backgroundColor = [UIColor clearColor];
[superView addSubview:pl];
return pl;
} - (instancetype)init{
if (self=[super init]) {
self.itmeSize = CGSizeMake(, );
}
return self;
} - (void)setItmeSize:(CGSize)itmeSize{
_itmeSize = itmeSize;
_width = itmeSize.width;
_height = itmeSize.height;
}
//设置图片形式
- (void)setImage:(UIImage *)image andSelectImage:(UIImage *)slectImage totalNum:(NSInteger)totalNum{
_isImage = YES;
_image = image;
_selectedImage = slectImage; _pageItems = [[NSMutableArray alloc]init];
NSInteger num = totalNum; NSInteger height = ;
NSInteger width =;
if (self.itmeSize.height!=&&self.itmeSize.width!=) {
height = self.itmeSize.height;
width = self.itmeSize.width;
}
NSInteger sepreate = ;
NSInteger totalWidth = num*width+(num-)*sepreate;
NSInteger orangex = (self.frame.size.width-totalWidth)/;
NSInteger orangey = (self.frame.size.height - height)/;
for (int i = ;i< num; i++) {
UIImageView * pageView = [[UIImageView alloc]init];
pageView.frame = CGRectMake(orangex+i*(width+sepreate), orangey, width, height);
[_pageItems addObject:pageView];
[self addSubview:pageView];
}
self.correntPage = ;
} //设置颜色形式
- (void)setColor:(UIColor *)color andSelectColor:(UIColor*)selectColor totalNum:(NSInteger)totalNum{
_pageItems = [[NSMutableArray alloc]init];
_color = color;
_selectedColor = selectColor; NSInteger num = totalNum;
NSInteger height = ;
NSInteger width =;
if (self.itmeSize.height!=&&self.itmeSize.width!=) {
height = self.itmeSize.height;
width = self.itmeSize.width;
}
NSInteger sepreate = ;
NSInteger totalWidth = num*width+(num-)*sepreate;
NSInteger orangex = (self.frame.size.width-totalWidth)/;
NSInteger orangey = (self.frame.size.height - height)/;
for (int i = ;i< num; i++) {
UIView * pageView = [[UIView alloc]init];
pageView.frame = CGRectMake(orangex+i*(width+sepreate), orangey, width, height);
[_pageItems addObject:pageView];
[self addSubview:pageView];
}
self.correntPage = ;
} - (void)setCorrentPage:(NSInteger)correntPage{
_correntPage = correntPage;
for (int i = ; i<_pageItems.count; i++) {
if (_isImage) {
UIImageView * imageView= _pageItems[i];
imageView.image = _image;
if (correntPage==i) {
imageView.image = _selectedImage;
}
}else{
UIView * view = _pageItems[i];
view.backgroundColor = _color;
if (correntPage==i) {
view.backgroundColor = _selectedColor;
}
}
}
} @end
最新文章
- C#双链表
- Docker 安装及命令
- IOS的APNS和PushKit门道详述
- 给网卡配置10个临时ip地址,但是不配置192.168.17.15这个ip
- 25.usb固件深入
- IOS学习网站
- linux - 怎么自动填写有交互的shell脚本 - SegmentFault
- 拥抱ARM妹子第二季 之 序:我和春天有个约会 - 生命的萌芽
- HDU1878欧拉回路
- 基于visual Studio2013解决C语言竞赛题之0612递归
- Python装饰器实现几类验证功能做法
- Jenkins具体安装与构建部署使用教程
- Nodejs使用redis
- CF 1013E Hills
- Spring学习笔记--Spring简介
- 【BZOJ-1493】项链工厂 Splay
- 2018.08.19 NOIP模拟 number(类数位dp)
- jquery on() bind()绑定的点击事件在js动态新添加的元素生效
- 10-19C#基础--第四部分类型(2)重点
- 汕头市队赛 SRM13 T3