English 中文(简体)
UIPageControl dot for a search page
原标题:

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?

最佳回答

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.

问题回答

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;
    }
}




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签