分享一个基于Swift3.0的ios入门学习Demo
来源:互联网 发布:mac如何查看应用程序 编辑:程序博客网 时间:2024/06/05 22:39
分享一个基于Swift3.0的ios入门学习Demo
看Swift基础有一段时间了,但是很少实践,最近准备抽时间把ios的基础过一遍,就给自己设计了这样一套作业(还有很多没完成,后续更新)。根据以前android的自学经验,入门涉及UI组件基础、自定义组件、数据存储、线程、网络、多媒体,当然你还有可能接触游戏开发。
目前工程已经涉及到Autolayout、网络、json和一些基本UI组件的使用,还有一些线程的使用(之前学习线程有单独写过帖子,这次就没有专门做这部分),以下是部分事例代码。
@objc func showCustom() { let customAlert = UIAlertController(title: "登陆", message: "请输入用户名跟密码", preferredStyle: .alert) customAlert.addTextField{ (textfield: UITextField) -> Void in textfield.placeholder="输入用户名" } customAlert.addTextField{ (textfield: UITextField) -> Void in textfield.placeholder="输入密码" } let oneAction = UIAlertAction(title: "取消", style: .cancel, handler: nil) let twoAction = UIAlertAction(title: "登陆", style: .destructive, handler: nil) customAlert.addAction(oneAction) customAlert.addAction(twoAction) controller?.present(customAlert, animated: true, completion: nil)}
override func loadUi(controller: UIViewController) { super.loadUi(controller: controller) guard let rootView = controller.view else { return } //UISlider slider = UISlider() AutoLayoutUtils.utils.setView(view: slider, parent: rootView) .markSize(height: 60) .markTo(toView: rootView) .mark(top: 72, leading: 6, trailing: -6) .cimmit() slider!.minimumValue = 0 slider!.maximumValue = 1 slider!.value = 0.5 //设置滑块停止后通知改变 默认true// slider.isContinuous = false slider!.addTarget(self, action: #selector(WidgetsLoader_01.sliderValueChanged(slider:)), for: .valueChanged) //UIProgressView progress = UIProgressView() AutoLayoutUtils.utils.setView(view: progress, parent: rootView) .markSize(height: 5) .markTo(toView: slider) .align(top: 10) .mark(leading: 6, trailing: -6, to: rootView) .cimmit() progress!.progress = 0.5 let label = UILabel() AutoLayoutUtils.utils.setView(view: label, parent: rootView) .markSize(width: 280, height: 60) .markTo(toView: progress) .align(top: 6) .mark(leading:0) .cimmit() label.text = "slider变化是否在滑块停止后更新" //UISwitch let sw = UISwitch() AutoLayoutUtils.utils.setView(view: sw, parent: rootView) .mark(centerY: 0, to: label) .mark(trailing: 0, to: progress) .cimmit() sw.addTarget(self, action: #selector(WidgetsLoader_01.swithDidChanged(swith:)), for: .valueChanged) //UISegmentedControl let items = ["第一项","第二项","第三项"] let segmentCtl = UISegmentedControl(items: items) AutoLayoutUtils.utils.setView(view: segmentCtl, parent: rootView) .align(top: 10, to: label) .mark(centerX: 0, to: rootView) .cimmit() // segmentCtl.addTarget(self, action: #selector(WidgetsLoader_01.segmentDidChanged(segment:)), for: .valueChanged) segmentCtl.selectedSegmentIndex = 0 self.segmentCtl = segmentCtl let segmentStateLabel = UILabel() segmentStateLabel.text="选择了第0项" AutoLayoutUtils.utils.setView(view: segmentStateLabel, parent: rootView) .markSize(width: 200, height: 40) .align(top: 2, to: segmentCtl) .mark(centerX: 0, to: rootView) .cimmit() segmentStateLabel.textAlignment = .center self.segmentStateLabel = segmentStateLabel let addBtn = UIButton() addBtn.setTitle("添加", for: .normal) addBtn.setTitleColor(UIColor.blue, for: .normal) addBtn.setTitleColor(UIColor.green, for: .highlighted) addBtn.addTarget(self, action: #selector(WidgetsLoader_01.addItem), for: .touchUpInside) AutoLayoutUtils.utils.setView(view: addBtn, parent: rootView) .markSize(width: 100, height: 30) .align(top: 2, to: segmentStateLabel) .mark(leading: 0, to: segmentCtl) .cimmit() let deleteBtn = UIButton() deleteBtn.setTitle("删除", for: .normal) deleteBtn.setTitleColor(UIColor.blue, for: .normal) deleteBtn.setTitleColor(UIColor.green, for: .highlighted) deleteBtn.addTarget(self, action: #selector(WidgetsLoader_01.removeItem), for: .touchUpInside) AutoLayoutUtils.utils.setView(view: deleteBtn, parent: rootView) .markSize(width: 100, height: 30) .align(top: 2, to: segmentStateLabel) .mark(trailing: 0, to: segmentCtl) .cimmit()}
func get(url: String, callback: @escaping (_ weather: [String: Any]?)->()) { let url = URL(string: url) let session = URLSession(configuration: URLSessionConfiguration.default) let task = session.dataTask(with: url!, completionHandler: { (data: Data?, reponse: URLResponse?, error: Error?) -> Void in if error == nil { do { let dict = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers) as? [String: Any] DispatchQueue.main.async{ let weatherinfo = dict?["weatherinfo"] as? [String: Any] for (name, value) in weatherinfo! { print("name : \(name) value : \(value)") } callback(weatherinfo) } } catch { } } }) operationQueue.addOperation(){ task.resume() }}
下载:http://download.csdn.net/detail/qin8752/9692740
0 0
- 分享一个基于Swift3.0的ios入门学习Demo
- ios 一个不错的图片浏览分享框架demo
- swift3.0 coreData的使用-日记本demo
- 基于swift3.0的网络请求
- Swift3.0 GCD定时器的使用,实现倒计时,UIDatePicker的使用, 仿写一个活动倒计时的DEMO
- 分享一个基于asp.net后台的QQ第三方接口demo
- 分享一个漂亮的WebGL demo
- swift3.0友盟分享
- IOS GCD Swift3.0
- IOS 分享 牛人 Demo
- iOS开发学习笔记之swift3.0几种加载网络图片的方法
- swift3.0 入门学习笔记之一 基础篇
- swift3.0 入门学习笔记之二 闭包
- Swift3.0学习实践-实现一个简单的数据持久化类(上)
- Swift3.0学习实践-实现一个简单的数据持久化类(下)
- Swift3.0学习实践-一个简单的画板(七色轨迹、可撤销、可清除、带橡皮擦)
- [iOS Swift3.0变化]iOS Swift3.0和2.3的区别
- 学习swift3.0的一些问题
- 使用fgetc实现fgets的功能 参数与返回值的含义,同fgets
- FLEX详解
- AngularJS循环绑定相关使用详解
- java中Map,List与Set的区别
- iOS UITableView的刷新和编辑
- 分享一个基于Swift3.0的ios入门学习Demo
- Atitit 图像处理知识点 知识体系 知识图谱
- 制作mysql的docker镜像
- select_tag
- Eclipse 安装Gradle插件
- 矩阵基本概念
- Flex样式工作原理
- python os.open() 和open()
- 开发中可能会碰到的null的坑