自定义滚动控件(Pagecontrol)
//
// 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
自定义滚动控件(Pagecontrol)的更多相关文章
- [android] 手机卫士自定义滚动控件
TextView控件设置单行显示 android:singleLine=”true” 设置TextView开始的位置显示省略号,android:ellipsize=”start” 设置滚动属性,and ...
- Android实现图片轮显效果——自定义ViewPager控件
一.问题概述 使用ViewPager控件实现可横向翻页.水平切换图片等效果,但ViewPager需要手动滑动才能切换页面,图片轮显效果的效果本质上就是在ViewPager控件的基础上让它能自动的进行切 ...
- 安卓自定义组合控件--toolbar
最近在学习安卓APP的开发,用到了toolbar这个控件, 最开始使用时include layout这种方法,不过感觉封装性不好,就又改成了自定义组合控件的方式. 使用的工具为android stud ...
- Android自定义控件之自定义组合控件
前言: 前两篇介绍了自定义控件的基础原理Android自定义控件之基本原理(一).自定义属性Android自定义控件之自定义属性(二).今天重点介绍一下如何通过自定义组合控件来提高布局的复用,降低开发 ...
- asp.net webform 自定义分页控件
做web开发一直用到分页控件,自己也动手实现了个,使用用户自定义控件. 翻页后数据加载使用委托,将具体实现放在在使用分页控件的页面进行注册. 有图有真相,给个直观的认识: 自定义分页控件前台代码: & ...
- arcgis api for js共享干货系列之二自定义Navigation控件样式风格
arcgis api for js默认的Navigation控件样式风格如下图: 这样的风格不能说不好,各有各的爱好,审美观,这里也不是重点,这里的重点是如何自定义一套自己喜欢的样式风格呢:自己自定义 ...
- C# DataGridView自定义分页控件
好些日子不仔细写C#代码了,现在主要是Java项目,C#.Net相关项目不多了,有点手生了,以下代码不足之处望各位提出建议和批评. 近日闲来无事想研究一下自定义控件,虽然之前也看过,那也仅限于皮毛,粗 ...
- C# 自定义FileUpload控件
摘要:ASP.NET自带的FileUpload控件会随着浏览器的不同,显示的样式也会发生改变,很不美观,为了提高用户体验度,所以我们会去自定义FileUpload控件 实现思路:用两个Button和T ...
- C#Winform VScrollBar+Pannel自定义列表控件(原)
该控件的主要实现思路是用的objective-c中的自定义控件思路,主视图中放子视图 效果图 (窗体调用代码) public partial class Form1 : RibbonForm { Li ...
随机推荐
- c#Winform程序,让pictureBox显示图像(包含GIF),并且不被占用,能即时删除图片。
最近在做一个图片浏览的工具, 需要在PictureBox中显示图像文件, 包括gif播放. 且不能被程序独占, 就算winform的程序正在显示这张图, 也能在资源管理器里delete它. 看了看网 ...
- How to: Modify a Project System So That Projects Load in Multiple Versions of Visual Studio
http://msdn.microsoft.com/en-us/library/hh266706(v=VS.110).aspx
- HDU 3666 THE MATRIX PROBLEM (差分约束,最短路)
题意: 给一个n*m矩阵,每个格子上有一个数字a[i][j],给定L和U,问:是否有这样两个序列{a1...an}和{b1...bn},满足 L<=a[i][j]*ai/bj<=U .若存 ...
- Dom文档模型
文档对象模型 通过 JavaScript,您可以重构整个 HTML 文档.您可以添加.移除.改变或重排页面上的项目.要改变页面的某个东西,JavaScript 就需要获得对 HTML 文档中所 ...
- DelegatingFilterProxy
安全过滤器链 Spring Security的web架构是完全基于标准的servlet过滤器的. 它没有在内部使用servlet或任何其他基于servlet的框架(比如spring mvc), 所以它 ...
- 【自动化测试】Selenium 2.0 学习笔记
定位下拉框元素,要记得先把鼠标挪过去再进行定位. 定位元素用的是find_element_by.... python的模块化还要去思考下 unittest框架使用的时候,py文件命名不要用unitte ...
- php生成 Arduino 12864 汉字内码
$ch = "你"; $ch = iconv("UTF-8","GB2312",$ch); $xx= sprintf("%X&qu ...
- Delphi 之前解析串口数据
//串口接收数据procedure TfrmClientMain.Comm1ReceiveData(Sender: TObject; Buffer: Pointer; BufferLength: Wo ...
- 提高CSS开发能力的技巧集
1. 使用:not()给导航条添加间隔线 我们通常使用如下代码给导航条增加间隔线 /* add border */ .nav li { border-right: 1px solid #666; } ...
- OSX学习02之更新输入法
OSX下最好的输入法是什么?话说在使用Windows的时候就知道了——它叫鼠须管. 想必大家用Windows的时候,进入系统第一步就是先装输入法吧~ OSX也是一样,自带输入法虽然凑合,但是我们作为A ...