前端之家收集整理的这篇文章主要介绍了
Swift PageControl,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
import UIKit
var arrColor:NSArray!
var testView:UIView!
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
arrColor = [UIColor.orangeColor(),UIColor.yellowColor(),UIColor.grayColor(),UIColor.blueColor()]
let pageControl = UIPageControl.init(frame: CGRectMake(50,70,self.view.frame.size.width-100,20))
pageControl.backgroundColor = UIColor.orangeColor()
pageControl.numberOfPages = 4
pageControl.currentPage = 0
pageControl.currentPageIndicatorTintColor = UIColor.redColor()
pageControl.addTarget(self,action: Selector("click:"),forControlEvents: UIControlEvents.ValueChanged)
self.view.addSubview(pageControl)
testView = UIView.init(frame: CGRectMake(10,120,self.view.frame.size.width-20,100))
testView.backgroundColor = UIColor.redColor()
self.view.addSubview(testView)
}
func click(sender:UIPageControl) {
testView.backgroundColor = arrColor[sender.currentPage] as? UIColor
}
}