新建一个类,继承UIPageControl类:
#import <UIKit/UIKit.h>
@interface UIBlackPageControl : UIPageControl
UIImage* activeImage;
UIImage* inactiveImage;
@end
在.m文件中定义初始化函数:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
// Initialization code
activeImage = [[UIImage imageNamed:@"novice_dot_press@2x.png"] retain];
inactiveImage = [[UIImage imageNamed:@"novice_dot_nor@2x.png"] retain];
[self setCurrentPage:1];
}
return self;
}
然后再将下面两个函数copy到你的.m文件中:
- (void)updateDots
{
for(int i = 0; i < [self.subviews count]; i++)
{
UIImageView* dot = [self.subviews objectAtIndex:i];
if(i == self.currentPage)
{
dot.image = _activeImage;
}
else
{
dot.image = _inactiveImage;
}
}
}
- (void)setCurrentPage:(NSInteger)page
{
[super setCurrentPage:page];
[self updateDots];
}
使用的时候只需要将这个类的头文件包含进来,使用方式与UIPageControl完全相同。
}
本文介绍如何通过创建自定义类来改变UIPageControl的外观,包括设置活动和非活动状态下的图片,并提供了具体的实现代码。
689

被折叠的 条评论
为什么被折叠?



