iphone - 如何更改 UIPageControl 点

标签 iphone objective-c interface-builder uipagecontrol

<分区>

我见过应用程序(例如 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/

相关文章:

swift - Xcode 6 中圆角矩形的问题

iphone - PhoneGap + iOS 异常 : [UIWebOverflowScrollView _viewDelegate] message sent to deallocated instance 0x21e330

iphone - 尝试在我的 iPad 上查看我的本地主机,这样我就不必先部署网站

iphone - 想要分享 MGTwitterEngine iPhone Xcode 框架项目吗?

ios - 重新定义模块 'Realm'

ios - 以编程方式使用大小类

iphone - 一键隐藏按钮

objective-c - 翻转、增长和翻译动画

ios - 在 UIWebView 中加载本地存储的图像

ios - UITableView - 仅在触摸时突出显示单个单元格