UIpageControl和NSTimer的属性

//UIPageControl //NSTimer属性

  • 1一共有多少页

  • 2,当前有多少页

  • 3,未选中滑块的颜色,选中滑块的颜色

  • 4,// 定时器 1. 间隔时间 2。 方法的执行对象
    // 3. 执行的方法 4. 配置信息, 类似备注
    // 5. true 循环执行 false 执行一次

  • 5 添加到主循环,初始化timer

  • 6 添加到驯化的某个形式

  • 7开启

  • 8,运行立即执行的方法

  • 9,当前的第几个小点点被选中

import UIKit

class ViewController: UIViewController {
    var timer:Timer! = nil
    
    //var timer = Timer()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //UIPageControl
        //NSTimer
        
        
        
        let page = UIPageControl()
        //一共多少页
        page.numberOfPages = 5
        //当前是多少页
        page.currentPage = 2
        //page.center = CGPoint(x: 100, y: 100)
        page.frame = CGRect(x: 100, y: 100, width: 100, height: 30)
        page.addTarget(self, action: #selector(pageAction(page:)), for: .valueChanged)
        self.view.addSubview(page)
        //未选中滑块的颜色
        page.pageIndicatorTintColor = UIColor.red
        //选中的滑块的颜色
        page.currentPageIndicatorTintColor = UIColor.gray
        
        
        // 定时器
        // 1. 间隔时间 2。 方法的执行对象
        // 3. 执行的方法 4. 配置信息, 类似备注
        // 5.  true 循环执行  false 执行一次
        timer = Timer(timeInterval: 1, target: self, selector: #selector(timerAction), userInfo: nil, repeats: true)
        // 添加到主循环  1. 初始化的timer
        //2. 添加到循环的某个模式中
        RunLoop.current.add(timer, forMode: .defaultRunLoopMode)
            //开启
        timer.fire()
        
        timer = Timer.scheduledTimer(timeInterval: 10, target : self, selector : #selector(timerAction), userInfo: nil, repeats: true)
        
    }
    //运行立即执行
    func timerAction () {
        print("1")
    }
    
    
    func pageAction(page:UIPageControl) {
        //当前第几个小点点被选中
       // print(page.currentPage)
        //定时器
        timer.invalidate()
       timer = nil
    }
    
    
    
    
    
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
}

你可能感兴趣的:(UIpageControl和NSTimer的属性)