设为首页 加入收藏

TOP

Swift-----类型转换 、 嵌套类型 、 扩展 、 协议 、 访问控制(三)
2017-10-10 12:17:31 】 浏览:2071
Tags:Swift----- 类型 转换 扩展 协议 访问 控制
on
= UIButton() resetButton.backgroundColor = UIColor.redColor() resetButton.setTitleColor(UIColor.whiteColor(), forState: .Normal) resetButton.setTitleColor(UIColor.blackColor(), forState: .Highlighted) resetButton.setTitle("Reset", forState: .Normal) view.addSubview(resetButton) resetButton.addTarget(self, action: "resetButtonTapped:", forControlEvents: .TouchUpInside) } func startButtonTapped(button:UIButton){ isCounting = !isCounting if isCounting { //添加消息推送 createAndFireLocalNotificationAfterSeconds(Double(remainingSeconds)) }else { //计时结束退出消息推送 UIApplication.sharedApplication().cancelAllLocalNotifications() } } func resetButtonTapped(button:UIButton){ remainingSeconds = 0 } //添加消息推送方法 func createAndFireLocalNotificationAfterSeconds(seconds:NSTimeInterval) { //取消之前所有的消息推送 UIApplication.sharedApplication().cancelAllLocalNotifications() let notification = UILocalNotification() //推送时间 notification.fireDate = NSDate(timeIntervalSinceNow: seconds) //推送时区 notification.timeZone = NSTimeZone.systemTimeZone() //推送通知的内容 notification.alertBody = "Time is up!" UIApplication.sharedApplication().scheduleLocalNotification(notification) } override func viewDidLoad() { super.viewDidLoad() setupTimeLabel() setupTimeButtons() setupActionButtons() } //布局代码 override func viewDidLayoutSubviews() { //时间窗口的布局 timeLabel.frame = CGRect(x: 10, y: 40, width: view.bounds.size.width-20, height: 120) //时间按钮的布局:按钮大小:64x44,按钮之间的间隔 let cnt = timeButtons.count - 1 let width = view.bounds.width - 10*2.0 - CGFloat(timeButtons.count) * 64.0 let gap = width / CGFloat(cnt) for (index, button) in enumerate(timeButtons) { let buttonLeft = 10.0 + CGFloat(index) * (64.0 + gap) button.frame = CGRectMake(CGFloat(buttonLeft), view.bounds.height-120.0, 64, 44) } //启动复位按钮的布局 startButton.frame = CGRectMake(10, view.bounds.height - 60, view.bounds.width - 20 - 100, 44) resetButton.frame = CGRectMake(10 + startButton.frame.width+20, view.bounds.height - 60, 80, 44) } }

 

首页 上一页 1 2 3 4 5 6 7 下一页 尾页 3/7/7
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇CocoaPods的安装和使用那些事(Xc.. 下一篇Swift语法笔记

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目