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,執(zhí)行的方法 4,配置信息 類似備注 5,true循環(huán)執(zhí)行 false 執(zhí)行一次
timer = Timer(timeInterval: 1, target: self, selector: #selector(timerAction), userInfo: nil, repeats: true)
//添加到主循環(huán) 1,初始化的timer 2,添加到循環(huán)的某個模式中
RunLoop.current.add(timer, forMode: .defaultRunLoopMode)
//開啟
timer.fire()
timer = Timer.scheduledTimer(timeInterval: 1, target : self, selector : #selector(timerAction), userInfo: nil, repeats: true)
}
//運行立即執(zhí)行
func timerAction () {
print("1")
}
func pageAction(page:UIPageControl) {
//當前第幾個小點點被選中
print(page.currentPage)
}
//定時器關(guān)閉
// timer.invalidate()
// timer = nil
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。