LoginSignup
7
8

More than 5 years have passed since last update.

お手軽に Instagram風PageControlを実装してみる

Posted at

作るもの

タイトル

FlexiblePageControlが便利

今回はshima11さんのFlexiblePageControlを使用して実装していきます

参考: https://github.com/shima11/FlexiblePageControl

Pods

pod "FlexiblePageControl", :git => "https://github.com/shima11/FlexiblePageControl.git"

Storyboard

UIViewから選択
表示させたい位置に配置してください
スクリーンショット 2018-05-19 15.20.26.png

Code

必要なものをIBOutletで接続

import FlexiblePageControl

class CardCell: UITableViewCell, UIScrollViewDelegate {

@IBOutlet weak var scrollView: UIScrollView!

@IBOutlet weak var flexiblePageControl: FlexiblePageControl!

pageControlの実装は特に難しくありません

        flexiblePageControl.numberOfPages = images.count
        flexiblePageControl.pageIndicatorTintColor = .gray
        flexiblePageControl.currentPageIndicatorTintColor = .blue
        flexiblePageControl.currentPage = 1

ScrollViewのDelegateで更新

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        flexiblePageControl.setProgress(contentOffsetX: scrollView.contentOffset.x, pageWidth: scrollView.bounds.width)
    }

おしまい

7
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
8