iOS学习六之UIPageControl

mac2022-06-30  133

分页视图

添加下面的代码即可完成

    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)

    }

转载于:https://www.cnblogs.com/minminjy123/p/9739649.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)