2016-04-20 12 views

答えて

9

UIPageViewControllerを使用すると、ドットはデフォルトで表示されます。私はあなたが白い背景を持っていると思います。そしてドットも白です。だからあなたはただそれらを見ません。

は、ドットの色を変更してください: 2.2

はスウィフト:

var appearance = UIPageControl.appearanceWhenContainedIn(UIPageViewController.self, nil) 
appearance.pageIndicatorTintColor = UIColor.redColor() 
appearance.currentPageIndicatorTintColor = UIColor.redColor() 

3.0スウィフト:

var appearance = UIPageControl.appearanceWhenContainedIn(UIPageViewController.self, nil) 
appearance.pageIndicatorTintColor = UIColor.red 
appearance.currentPageIndicatorTintColor = UIColor.red 

それは、必ずことを確認してください解決しない場合遷移スタイルUIPageViewControllerTransitionStyleScrollを使用しています。

+1

ありがとうございました!それは私のために働いた。 – Himanshu

+1

喜んで助けてください:) – KlimczakM

+1

私のUIPageViewControllerのトランジションスタイルを変更すると、この問題が修正されました。ありがとうございました! –

1

、ドットをUIPageViewController示し、その後presentationCountForPageViewControllerpresentationIndexForPageViewControllerデータソースのメソッドを使用し

SWIFTコード:

private func setupPageControl() { 
     let appearance = UIPageControl.appearance() 
     appearance.pageIndicatorTintColor = UIColor.grayColor() 
     appearance.currentPageIndicatorTintColor = UIColor.whiteColor() 
     appearance.backgroundColor = UIColor.darkGrayColor() 
    } 

func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int 
    { 
    setupPageControl() 
    return self.arrimg.count 
    } 

    func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int 
    { 
    return 0 
    } 

Objective-Cのコード:

- (void) setupPageControl 
{ 
    [[UIPageControl appearance] setPageIndicatorTintColor: [UIColor lightGrayColor]]; 
    [[UIPageControl appearance] setCurrentPageIndicatorTintColor: [UIColor blackColor]]; 
    [[UIPageControl appearance] setTintColor: [UIColor blackColor]]; 

} 

- (NSInteger) presentationCountForPageViewController: (UIPageViewController *) pageViewController 
{ 
    [self setupPageControl]; 
    return [arrimg count]; 
} 

- (NSInteger) presentationIndexForPageViewController: (UIPageViewController *) pageViewController 
{ 
    return 0; 
} 

私のためにその作業、そのが参考に願っています

+1

あなたが私にそれを変えると言ったら、私の答えには何が間違っていますか? –

+0

それは働いています。しかし、私は別々の関数setupPageControl()を望んでいません。私はviewDidLoad()メソッドでこれらのコード行を使用しました。 – Himanshu

+0

でも、別の関数setupPageControl()を使用して呼び出す必要がある場合は、 –

11

Swift 3.0では、 D:

private func setupPageControl() { 
    let appearance = UIPageControl.appearance() 
    appearance.pageIndicatorTintColor = UIColor.gray 
    appearance.currentPageIndicatorTintColor = UIColor.white 
    appearance.backgroundColor = UIColor.darkGray 
} 

func presentationCount(for pageViewController: UIPageViewController) -> Int { 
    setupPageControl() 
    return self.images.count 
} 

func presentationIndex(for pageViewController: UIPageViewController) -> Int { 
    return 0 
} 
2

ModelControllerクラスに挿入したときに、次のコードが動作するのXcode 7でページベースのアプリケーションテンプレート使用して:私は、誰もがまだ質問のこの種を探している場合は

func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int { 
    setupPageControl() 
    return self.pageData.count 
} 

func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int { 
    return 0 
} 

private func setupPageControl() { 
    let appearance = UIPageControl.appearance() 
    appearance.pageIndicatorTintColor = UIColor.grayColor() 
    appearance.currentPageIndicatorTintColor = UIColor.whiteColor() 
    appearance.backgroundColor = UIColor.darkGrayColor() 
} 
4

UIPageViewControllerにページのドットを追加する方法についての良いチュートリアルを見つけました。それは少なくとも私のために働いた。

http://www.seemuapps.com/page-view-controller-tutorial-with-page-dots

これは、この質問に関連する部分である:

は、次のようにpageControlを追加するには、ページのドット表示を追加するには、適切なデリゲートとデータソース

import UIKit 

class PageViewController: UIPageViewController, UIPageViewControllerDelegate, UIPageViewControllerDataSource 

を持っていることを確認してください:

UIPageControlのインスタンスを作成します。

var pageControl = UIPageControl() 

ここで次の機能を追加します。これにより、ページコントロールが画面の下部に配置されます。現在のページの表示は黒で残りのインジケーターは白です。これらは、アプリのデザインに合わせて変更できます。

func configurePageControl() { 
    pageControl = UIPageControl(frame: CGRect(x: 0,y: UIScreen.main.bounds.maxY - 50,width: UIScreen.main.bounds.width,height: 50)) 
    self.pageControl.numberOfPages = orderedViewControllers.count 
    self.pageControl.currentPage = 0 
    self.pageControl.alpha = 0.5 
    self.pageControl.tintColor = UIColor.black 
    self.pageControl.pageIndicatorTintColor = UIColor.white 
    self.pageControl.currentPageIndicatorTintColor = UIColor.black 
    self.view.addSubview(pageControl) 
} 

viewDidLoad()に次の2行を追加します。あなたはスクロールとして

self.delegate = self 
configurePageControl() 

をまた、以下の機能を追加し、これが正しいページに確認ページ制御インジケータの変更を行います。

// MARK: Delegate functions 
func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) { 
    let pageContentViewController = pageViewController.viewControllers![0] 
    self.pageControl.currentPage = orderedViewControllers.index(of: pageContentViewController)! 
} 
+0

答えにはちょっとした説明だけが必要です。それがStackOverflowのようなものです: – sniperd

+0

チップをありがとう!あなたの提案通りに自分の答えを更新しました。 – Josh

+0

「秘密」は、UIPageControlを追加する必要があることです。ありがとう、@ジョシュ – Verticon

関連する問題