ui控件之UIPageControl

//  UIPageControl

//

//  Created by Catherine on 2017/8/30.

//  Copyright © 2017 Catherine. All rights reserved.

//


import UIKit


class ViewController: UIViewController {


    override func viewDidLoad() {

扫描二维码关注公众号,回复: 1060209 查看本文章

        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.

    }



}


猜你喜欢

转载自blog.csdn.net/catherine981234/article/details/77706259