5

有什么方法可以为我的第一页添加放大镜图标而不是点,从而允许在 iPhone 上使用我的本机应用程序的 UIPageControl 执行一些搜索?

我试过谷歌,但根本没有找到类似的问题,但它看起来像是 Apple 应用程序中广泛使用的功能。

有人可以帮我一个建议吗?

4

2 回答 2

6

基本上 UIPageControl 有一个_indicators数组,其中包含每个点的 UIView。这个数组是一个私有属性,所以你不应该弄乱它。如果您需要自定义图标,则必须自己实现页面指示器。

编辑:经过更多研究,您似乎可以替换 UIPageControl 子视图来自定义点图像。查看http://www.onidev.com/2009/12/02/customisable-uipagecontrol/了解详情。不过,仍然不确定 Apple 评论者会如何看待做这样的事情。

于 2009-11-21T23:10:21.653 回答
1

我创建了一个 UIPageControl 子类来轻松合法地实现这一点(无需私有 API)。基本上,我覆盖了 setNumberOfPages:在最后一个圆圈内插入带有图标的 UIImageView。然后在 setCurrentPage: 方法上,我检测最后一页是否突出显示,以修改 UIImageView 的状态并清除圆圈的背景颜色,因为这将由 UIPageControl 私有 API 自动更新。

这是结果: 在此处输入图像描述

这是代码:

@interface EPCPageControl : UIPageControl
@property (nonatomic) UIImage *lastPageImage;
@end

@implementation EPCPageControl

- (void)setNumberOfPages:(NSInteger)pages
{
    [super setNumberOfPages:pages];

    if (pages > 0) {

        UIView *indicator = [self.subviews lastObject];
        indicator.backgroundColor = [UIColor clearColor];

        if (indicator.subviews.count == 0) {

            UIImageView *icon = [[UIImageView alloc] initWithImage:self.lastPageImage];
            icon.alpha = 0.5;
            icon.tag = 99;

            [indicator addSubview:icon];
        }
    }
}

- (void)setCurrentPage:(NSInteger)page
{
    [super setCurrentPage:page];

    if (self.numberOfPages > 1 && self.lastPageImage) {

        UIView *indicator = [self.subviews lastObject];
        indicator.backgroundColor = [UIColor clearColor];

        UIImageView *icon = (UIImageView *)[indicator viewWithTag:99];
        icon.alpha = (page > 1 && page == self.numberOfPages-1) ? 1.0 : 0.5;
    }
}
于 2013-12-31T15:25:47.207 回答