重写UIPageControl实现自定义按钮
来源:互联网 发布:理财软件新闻 编辑:程序博客网 时间:2024/05/17 01:53
新建类继承UIPageControl :
MyPageControl.h文件:
@interface MyPageControl : UIPageControl
{
UIImage *imagePageStateNormal;
UIImage *imagePageStateHighlighted;
}
- (id)initWithFrame:(CGRect)frame;
@property (nonatomic, retain) UIImage *imagePageStateNormal;
@property (nonatomic, retain) UIImage *imagePageStateHighlighted;
@end
MyPageControl.m文件:
@interface MyPageControl(private) // 声明一个私有方法, 该方法不允许对象直接使用
- (void)updateDots;
@end
@implementation MyPageControl // 实现部分
@synthesize imagePageStateNormal;
@synthesize imagePageStateHighlighted;
- (id)initWithFrame:(CGRect)frame { // 初始化
self = [super initWithFrame:frame];
return self;
}
- (void)setImagePageStateNormal:(UIImage *)image { // 设置正常状态点按钮的图片
[imagePageStateNormal release];
imagePageStateNormal = [image retain];
[self updateDots];
}
- (void)setImagePageStateHighlighted:(UIImage *)image { // 设置高亮状态点按钮图片
[imagePageStateHighlighted release];
imagePageStateHighlighted = [image retain];
[self updateDots];
}//重写 setCurrentPage方法
- (void)setCurrentPage:(NSInteger)currentPage
{
[super setCurrentPage:currentPage];
[self updateDots];
}
- (void)updateDots { // 更新显示所有的点按钮
if (imagePageStateNormal || imagePageStateHighlighted)
{
NSArray *subview = self.subviews; // 获取所有子视图
for (NSInteger i = 0; i < [subview count]; i++)
{
UIImageView *dot = [subview objectAtIndex:i]; // 以下不解释, 看了基本明白
dot.image = self.currentPage == i ? imagePageStateNormal : imagePageStateHighlighted;
}
}
}
- (void)dealloc { // 释放内存
[imagePageStateNormal release], imagePageStateNormal = nil;
[imagePageStateHighlighted release], imagePageStateHighlighted = nil;
[super dealloc];
}
@end
调用:
MyPageControl *pageControl = [[MyPageControl alloc] initWithFrame:CGRectMake(0,0, 200, 30)];
pageControl.backgroundColor = [UIColor clearColor];
pageControl.numberOfPages = 5;
pageControl.currentPage = 0;
[pageControl setImagePageStateNormal:[UIImage imageNamed:@"pageControlStateNormal.png"]];
[pageControl setImagePageStateHighlighted:[UIImage imageNamed:@"pageControlStateHighlighted.png"]];
[self.view addSubview:pageControl];
[pageControl release];
- 重写UIPageControl实现自定义按钮
- 重写UIPageControl实现自定义按钮
- 重写UIPageControl实现自定义按钮
- UIPageControl实现自定义按钮
- UIPageControl实现自定义按钮
- UIPageControl实现自定义按钮
- iphone UIPageControl实现自定义按钮
- iPhone开发中UIPageControl实现自定义按钮
- UIPageControl 实现自定义样式
- UIPageControl 实现自定义样式
- UIPageControl 圆点背景图片的自定义实现
- 自定义UIPageControl
- 自定义UIPageControl
- UIPageControl自定义
- 自定义UIPageControl
- 自定义UIPageControl
- 自定义UIPageControl
- 自定义UIPageControl
- 阻抗匹配及其作用
- PCB中plane和layer的区别
- 与Iteye关联
- 生产者与消费者
- 【精】多层PCB层叠结构
- 重写UIPageControl实现自定义按钮
- 结合工具来实现敏捷开发 - 8
- oracle字符集
- 大头小头
- HIVE笔记
- PS2、USB、DB-9、网卡、串口、并口、VGA针脚定义及接口定义图
- 手动将mysql 服务添加到windows系统服务中
- 关于去耦电容和旁路电容
- Linux下开发优秀链接