<分区>
我见过应用程序(例如 meebo)在 UIPageControls 上有不同的指示器,而不是默认的白色圆圈。
有没有简单的方法来做到这一点?我已经阅读了 UIPageControls 的文档,似乎没有替换图像的方法。
<分区>
我见过应用程序(例如 meebo)在 UIPageControls 上有不同的指示器,而不是默认的白色圆圈。
有没有简单的方法来做到这一点?我已经阅读了 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 就在其中。
当加载 View 时,将设置 UIPageControl 图像。
关于iphone - 如何更改 UIPageControl 点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2673827/