2013-07-16 12 views
16

Hej Używam kontrolki UIPageViewController do kontrolowania strony, na której się znajduję i do przewijania. Wiem, że możliwe jest pokazanie kontrolera stron wraz z nim, po prostu dodając dwie następujące funkcje.Zmiana własnego kontrolera UIPageViewController dotyczącego koloru kropek

- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController 

- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController 

Co chcę wiedzieć, czy jest możliwe, aby zmienić kolor kontrolera widoku, więc punkty są bardziej widoczne na tle używam?

wiem regularne kontroler strona ma właściwości:

@property(nonatomic,retain) UIColor *currentPageIndicatorTintColor 
@property(nonatomic,retain) UIColor *pageIndicatorTintColor 

Jednak nie mogę dowiedzieć się o życiu mi jak uzyskać dostęp do tych właściwości lub strona kontroler dla tej sprawy z UIPageViewController.

Może być pomocne, jeśli ktoś właśnie powiedział, jak zmienić właściwości w ogóle?

Odpowiedz

51

Za pomocą UIAppearance można konfigurować kolory UIPageControl. Dotyczy to również UIPageControls w UIPageViewControllers też.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    UIPageControl *pageControl = [UIPageControl appearance]; 
    pageControl.pageIndicatorTintColor = [UIColor whiteColor]; 
    pageControl.currentPageIndicatorTintColor = [UIColor redColor]; 
} 
+1

Dzięki który pracował wielki! – Lightbarrier

+3

+1 To powinno mieć więcej wyświetleń i więcej głosów. Jest idealny! –

+0

Witam, dla tintColor jego działanie. czy możesz mi powiedzieć jak zmniejszyć wysokość UIPageControl (wypróbowałem 'pageControl.frame = CGRectMake (self.viewController.view.bounds.origin.x, self.viewController.view.bounds.origin.y + 352, self.viewController .view.bounds.size.width, 10); ') –

1

UIPageControl zgodny z protokołem UIAppearance. The Apple Developper API Reference stany o UIAppearance:

pomocą protokołu UIAppearance aby uzyskać proxy wygląd klasy. Możesz dostosować wygląd instancji klasy, wysyłając komunikaty o zmianie wyglądu na serwer proxy klasy.


Dlatego, korzystając Swift 2.2, można ustawić UIPageControl „s pageIndicatorTintColor i currentPageIndicatorTintColor w podklasie UINavigationController lub w klasie AppDelegate (bardziej globalnego podejścia).

CustomNavigationController.swift:

class CustomNavigationController: UINavigationController { 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     // Set pageIndicatorTintColor and currentPageIndicatorTintColor 
     // only for the following stack of UIViewControllers 
     let pageControl = UIPageControl.appearance() 
     pageControl.pageIndicatorTintColor = UIColor.blueColor() 
     pageControl.currentPageIndicatorTintColor = UIColor.greenColor() 
    } 

} 

AppDelegate.Swift:

class AppDelegate: UIResponder, UIApplicationDelegate { 

    var window: UIWindow? 

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 

     // Set pageIndicatorTintColor and currentPageIndicatorTintColor globally 
     let pageControl = UIPageControl.appearance() 
     pageControl.pageIndicatorTintColor = UIColor.blueColor() 
     pageControl.currentPageIndicatorTintColor = UIColor.greenColor() 

     return true 
    } 

} 
7

Jeśli chcesz zmienić barwy UIPageControl dotyczący konkretnego UIPageViewController, można użyć następujące:

w Swift 3

let pageControl: UIPageControl = UIPageControl.appearance(whenContainedInInstancesOf: [MyPageViewController.self]) 
pageControl.pageIndicatorTintColor = UIColor.green 
// ... any other changes to pageControl