// UIPageControl
//
// Created by Catherine on 2017/8/30.
// Copyright © 2017年 Catherine. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = UIColor.red
let page:UIPageControl = UIPageControl(frame: CGRect(x: 100, y: 100, width: 100, height: 100))
//设置page页数
page.numberOfPages = 6
//设置当前的页码---编号开始从0
page.currentPage = 3
//如果当前只有一页那么不显示小点
page.hidesForSinglePage = true
//设置分页控制器的当前页点点颜色
page.currentPageIndicatorTintColor = UIColor.brown
//设置所有的分页点的颜色
page.pageIndicatorTintColor = UIColor.purple
//添加方法
page.addTarget(self, action: #selector(change(page:)), for: UIControlEvents.valueChanged)
self.view.addSubview(page)
}
func change(page:UIPageControl){
print(page.currentPage)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}