搜索页面的 UIPageControl 点

发布于 2024-08-11 11:06:15 字数 154 浏览 4 评论 0原文

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

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

有人可以帮我提供建议吗?

Is there any way to add a magnification glass icon instead of the dot for my first page, that allows to perform some search, using the UIPageControl for my native application on the iPhone?

I've tried to google, but haven't find similar questions at all, but it looks like a wide-spread feature in Apple applications.

Can anybody help me with an advice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

王权女流氓 2024-08-18 11:06:15

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

编辑:经过更多研究,似乎您可以替换 UIPageControl 子视图来自定义点图像。检查 http://www.onidev.com/2009/12/02/customisable -uipagecontrol/ 了解详细信息。但仍不确定苹果评论者对这样做有何感想。

Basically UIPageControl has an _indicators array that contains UIViews for each of the dots. This array is a private property, so you should not mess with it. If you need custom icons, you will have to do your own page indicator implementation.

Edit: After some more research, it seems you can replace the UIPageControl subviews to customize the dot images. Check http://www.onidev.com/2009/12/02/customisable-uipagecontrol/ for details. Still not sure how Apple reviewers are going to feel about doing such thing though.

幽蝶幻影 2024-08-18 11:06:15

我创建了一个 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;
    }
}

I created an UIPageControl subclass to achieve this easily and legally (without private APIs).
Basically, I overwritten setNumberOfPages: insert a UIImageView with he icon inside of the last circle. Then on the setCurrentPage: method I detect if the last page gets highlighted or not, to modify the UIImageView's state and also, clear the background color of the circle since this will be updated automatically by UIPageControl private APIs.

This is the result:
enter image description here

This is the code:

@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;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文