Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I implement the page indicator from the IFTTT app? #35

Open
SikandAlex opened this issue Aug 25, 2016 · 3 comments
Open

How can I implement the page indicator from the IFTTT app? #35

SikandAlex opened this issue Aug 25, 2016 · 3 comments

Comments

@SikandAlex
Copy link

Is there an option to enable that page indicator at the bottom of the intro to IFTTT app?
screenshot_20160825-133355

@getaaron
Copy link

There's no built-in page control, but you can trivially create one:

let pageControl: UIPageControl = {
    let control = UIPageControl()
    control.translatesAutoresizingMaskIntoConstraints = false
    control.currentPage = 0
    control.pageIndicatorTintColor = UIColor.yellowColor()
    control.currentPageIndicatorTintColor = UIColor.purpleColor()
    return control
}()

Configure it in viewDidLoad:

pageControl.numberOfPages = 4 // make sure this is correct

view.addSubview(pageControl)

// constrain the page control's location
NSLayoutConstraint(item: pageControl, attribute: .Bottom, relatedBy: .Equal, toItem: contentView, attribute: .Bottom, multiplier: 1, constant: -20).active = true
NSLayoutConstraint(item: pageControl, attribute: .CenterX, relatedBy: .Equal, toItem: view, attribute: .CenterX, multiplier: 1, constant: 0).active = true

Finally, in the scroll view delegate, update the current page:

override func scrollViewDidScroll(scrollView: UIScrollView) {
    animator.animate(scrollView.contentOffset.x)

    // …

    let currentPage = Int(scrollView.contentOffset.x / pageWidth)
    pageControl.currentPage = currentPage
}

@nharbo
Copy link

nharbo commented Apr 20, 2017

This if fucking up the animations :) .. It shows the pagecontrol, but its not working properly

@ghost
Copy link

ghost commented Jul 30, 2017

@nharbo instead of complaining, you can look into the implementation and if you didn't do that, here is how you can fix it : Just call super.scrollViewDidScroll(scrollView) and animation should work fine again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants