如何更改UIPageControl点 [英] how to change UIPageControl dots

查看:90
本文介绍了如何更改UIPageControl点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过的应用程序(例如meebo)在UIPageControls上有不同的指标,而不是默认的白色圆圈。

I've seen apps (e.g. meebo) that have different indicators on UIPageControls instead of the default white circles.

有一个简单的方法吗?我已经阅读了UIPageControls的文档,似乎没有方法可以替换图像。

is there an easy way to do this? I've read the docs for UIPageControls and it seems that there is no methods to replace the images.

推荐答案

你可以实现这一点通过执行以下步骤:

You can achieve this by making the following steps:

1-创建一个继承自UIPageControl的自定义类。

1- Create a custom class that inherits from UIPageControl.

2-分配此类到您想要更改其点的所需UIPageControl。

2- Assign this class to the required UIPageControl that you want to change its dots.

3-将以下代码放入自定义UIPageControl类中。

3- Put the following code inside your custom UIPageControl class.

将它放在customClass.m文件中:

Put this in the customClass.m file:

-(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文件中

Put this in the customClass.h file

{
    UIImage* activeImage;
    UIImage* inactiveImage;
}
@property(nonatomic, retain) UIImage* activeImage;
@property(nonatomic, retain) UIImage* inactiveImage;

5-只需在将页面控件放入其中的类中设置UIPageControl的当前页面使用以下行:

5- Just set the current page of your UIPageControl in the class that you put the page control inside it using the following line:

[self.pageControl setCurrentPage:number];

记得在UIPageControl里面的viewDidLoad()方法中设置当前页面。

remember to set the current page in the viewDidLoad() method in the view of that UIPageControl is inside it.

当加载视图时,将设置UIPageControl图像。

When the view loaded the UIPageControl images will be set.

这篇关于如何更改UIPageControl点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆