分页视图
添加下面的代码即可完成
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//背景色设置成蓝色
self.view.backgroundColor = UIColor.blue
//分页控件的位置和大小
let page = UIPageControl(frame: CGRect(x:20, y:100, width:280, height:30))
//当前页的圆点设置为黄色
page.currentPageIndicatorTintColor = UIColor.yellow
//圆点变化时回调changeNum方法,点击分页控件右侧,圆点会向右变化,点击分页控件左侧,圆点会向左变化
page.addTarget(self, action: #selector(changeNum), for: .valueChanged)
//设置总页数为8页
page.numberOfPages = 8
self.view.addSubview(page)
}
//圆点位置变化回调方法
@objc func changeNum(page:UIPageControl) {
print(page.currentPage)
}