我见过在 UIPageControls 上有不同指示符的应用程序(例如 meebo),而不是默认的白色圆圈。
是否有捷径可寻?我已经阅读了 UIPageControls 的文档,似乎没有替换图像的方法。
我见过在 UIPageControls 上有不同指示符的应用程序(例如 meebo),而不是默认的白色圆圈。
是否有捷径可寻?我已经阅读了 UIPageControls 的文档,似乎没有替换图像的方法。
您可以通过以下步骤实现此目的:
1- 创建一个继承自 UIPageControl 的自定义类。
2-将此类分配给您要更改其点的所需 UIPageControl。
3-将以下代码放入您的自定义 UIPageControl 类中。
把它放在 customClass.m 文件中:
-(id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if(self)
{
activeImage = [UIImage imageNamed:@"active_dot.png"];
inactiveImage = [UIImage imageNamed:@"inactive_dot.png"];
}
return self;
}
-(void)updateDots
{
for (int i = 0; i < [self.subviews count]; i++)
{
UIImageView* dot = [self.subviews objectAtIndex:i];
dot.frame = CGRectMake(dot.frame.origin.x, dot.frame.origin.y, 14, 14.5);
if (i == self.currentPage)
dot.image = activeImage;
else
dot.image = inactiveImage;
}
}
-(void)setCurrentPage:(NSInteger)page
{
[super setCurrentPage:page];
[self updateDots];
}
把它放在 customClass.h 文件中
{
UIImage* activeImage;
UIImage* inactiveImage;
}
@property(nonatomic, retain) UIImage* activeImage;
@property(nonatomic, retain) UIImage* inactiveImage;
5- 只需使用以下行在将页面控件放入其中的类中设置 UIPageControl 的当前页面:
[self.pageControl setCurrentPage:number];
记得在 viewDidLoad() 方法中设置当前页面在 UIPageControl 的视图中。
当视图加载 UIPageControl 图像将被设置。
没有公共 API 来更改图像。您可以查看这篇博客文章,该文章描述了一种自定义UIPageControl的方法。