I know this question is a common one. But I have not found a working solution in Swift, only vague (to me) instructions. Here's one example question: https://forums.developer.apple.com/message/73732. There are many more at StackOverflow and elsewhere. I've even found instructions on how to rotate the dot display to vertical.
The default dots are nice but too small, in my opinion, for a tutorial. The user may miss them and not realize how to proceed. I want mine to be bigger, maybe twice as big, and I'd like control over the dot colors while I'm at it.
I have a single UIPageViewController with a single view controller under it's control, see below. It works beautifully, except for the small size of the dots. Each tutorial page gets an image and a text block.
If I add a UIPageControl to the subservient view controller containing the image and text views, I can control the size and the dot colors. But the default controller still shows and is not affected. How can I seize control of the default dots, or hide them so I can replace them with my own? I should add that I don't need to change the relative spacing between the dots, I just want the whole thing larger. "pageControl.transform = CGAffineTransform(scaleX: 2, y: 2)" works fine on my custom UIPageControl.
import UIKit
class ManagePageViewController: UIPageViewController {
var photos = ["photo1", "photo2", "photo3", "photo4", "photo5"]
var currentIndex: Int!
var textFields = ["pageText1", "pageText2", "pageText3", "pageText4", "pageText5"]
override func viewDidLoad() {
super.viewDidLoad()
dataSource = self
if let viewController = tutorialController(currentIndex ?? 0) {
let viewControllers = [viewController]
setViewControllers(viewControllers,
direction: .forward,
animated: false,
completion: nil)
}
}
func tutorialController(_ index: Int) -> myTutorialViewController? {
if let storyboard = storyboard,
let page = storyboard.instantiateViewController(withIdentifier: "myTutorialViewController") as? myTutorialViewController {
page.photoName = photos[index]
page.photoIndex = index
page.textName = textFields[index]
page.textIndex = index
return page
}
return nil
}
}
extension ManagePageViewController: UIPageViewControllerDataSource {
func pageViewController(_ pageViewController: UIPageViewController,
viewControllerBefore viewController: UIViewController) -> UIViewController? {
if let viewController = viewController as? PhotoCommentViewController,
let index = viewController.photoIndex,
index > 0 {
return viewPhotoCommentController(index - 1)
}
return nil
}
func pageViewController(_ pageViewController: UIPageViewController,
viewControllerAfter viewController: UIViewController) -> UIViewController? {
if let viewController = viewController as? myTutorialViewController,
let index = viewController.photoIndex,
(index + 1) < photos.count {
return tutorialController(index + 1)
}
return nil
}
func presentationCount(for pageViewController: UIPageViewController) -> Int {
return photos.count
}
func presentationIndex(for pageViewController: UIPageViewController) -> Int {
return currentIndex ?? 0
}
}
This code in my view controller works fine to control an added UIPageControl, but I can't get ahold of the default one:
func configurePageControl() {
self.pageControl.numberOfPages = 5
self.pageControl.currentPage = photoIndex
pageControl.transform = CGAffineTransform(scaleX: 2, y: 2); // Looks better!
self.pageControl.tintColor = UIColor.blue // This does nothing?
self.pageControl.pageIndicatorTintColor = UIColor.red
self.pageControl.currentPageIndicatorTintColor = UIColor.black
self.view.addSubview(pageControl)
}