Reputation: 6413
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?
Upvotes: 5
Views: 3153
Reputation: 4878
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:
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;
}
}
Upvotes: 1
Reputation: 126
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.
Upvotes: 6