2009-11-19 101 views
6

有什麼辦法可以在我的第一頁上添加一個放大鏡圖標而不是點,它允許執行一些搜索,使用UIPageControl作爲iPhone上的本機應用程序?搜索頁面的UIPageControl點

我試過谷歌,但一直沒有找到類似的問題,但它看起來像蘋果應用程序中的一個廣泛的功能。

有人能幫我一個建議嗎?

回答

7

基本上UIPageControl有一個_indicators數組,其中包含每個點的UIViews。這個數組是一個私有屬性,所以你不應該搞砸它。如果你需要自定義圖標,你將不得不做自己的頁面指標實現。

編輯:經過一些更多的研究,似乎你可以替換UIPageControl子視圖來定製點圖像。詳情請查詢http://www.onidev.com/2009/12/02/customisable-uipagecontrol/。儘管如此,蘋果評論家仍然不確定如何去做這件事。

+0

謝謝您的回答!我希望到最後它不會以這種方式: -/ – Denis 2009-11-24 08:10:35

+0

我已經實現了我的目標,在搜索圖標上方添加了UIPageControl的子視圖(必須花費一些時間才能找到它的放置算法) 。它按需要工作。無論如何,我不得不責備蘋果方面不允許這種定製開箱即用。 – Denis 2010-02-01 16:47:10

+1

我們已經使用您提供的鏈接中描述的技術提交了應用程序,沒有任何問題。 – hennes 2011-04-12 15:48:20

1

我創建了一個UIPageControl子類,以實現這一點,並且合法(無私有API)。 基本上,我覆蓋了setNumberOfPages:在最後一個圓圈內插入一個帶有他圖標的UIImageView。然後,在setCurrentPage:方法中,我檢測最後一頁是否突出顯示,以修改UIImageView的狀態,並清除圓圈的背景顏色,因爲這將由UIPageControl私有API自動更新。

這是結果: enter image description here

這是代碼:

@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; 
    } 
} 
+0

謝謝。這幫了我很多。我發現它比另一種方法更清潔! – kekub 2014-08-04 10:47:06