1. 使用资源文件夹导入并管理图片素材

/*

*资源文件夹可以方便您进行图片管理,在读取图片时,不需要加上图片名的后缀.同时还可以提高软件的安全性,它会讲图片都加密压缩,

*并保存到   Assets.car文件中.

*/

//创建一个图像类,用于加载和绘制图像.

let img = UIImage(named: "Pic2.png")  //待测(XCode):let img = UIImage(named: "Pic2")

let imgView = UIImageView(image: img)

self.view.addSubview(imgView)

2. 应用程序生命周期

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

// Override point for customization after application launch.

//将程序载入后需要执行的代码,写在程序完成加载的方法里面,常用方法

print(">>>didFinishLaunchingWithOptions")

return true

}

func applicationWillResignActive(application: UIApplication) {

// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

//非活动状态,期间,程序不接受消息和事件

print(">>>applicationWillResignActive")

}

func applicationDidEnterBackground(application: UIApplication) {

// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

//程序被推送到后台的时候,调用次方法,若设置后台继续某些动作,则在这个方法里面添加代码即可

print(">>> applicationDidEnterBackground")

}

func applicationWillEnterForeground(application: UIApplication) {

// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

//后台 -> 前台

}

func applicationDidBecomeActive(application: UIApplication) {

// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

//进入活动状态时,执行此方法

}

func applicationWillTerminate(application: UIApplication) {

// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

//程序将要退出时,调用此方法. 通常是用来保存数据,和一些退出前的清理工作

}

3 快速查找并打开文件

//1. 选择[快速打开]子菜单,快速查找项目文档,当你工作一个庞大的项目中时,这个功能会为你提供很大便利

//2. 点击键盘上的按钮,输入关键字来过滤文档

//快捷键方式: Command + Shift + O

4. 快速更改同名变量

//在代码的编辑区域,点击定位需要更改名称的变量

//打开菜单栏中的编辑菜单 -> 选择重构此菜单 -> 选择重命名命令,此命令允许统一修改文档中的某个变量. -> 在名称框输入新的名称

5. 代码的查找和替换

6. 视图的基本使用

let rect1 = CGRect(x: 30, y: 50, width: 200, height: 200)

let view1 = UIView(frame: rect1)

view1.backgroundColor = UIColor.brownColor()

let rect2 = CGRect(x: 90, y: 120, width: 200, height: 200)

let view2 = UIView(frame: rect2)

view2.backgroundColor = UIColor.purpleColor()

self.view.addSubview(view1)

self.view.addSubview(view2)

7. 视图的层次关系

let view1 = UIView(frame: CGRect(x: 20, y: 80, width: 280, height: 280))

view1.backgroundColor = UIColor.redColor()

self.view.addSubview(view1)

let view2 = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))

//设置视图本地坐标系统中的位置和大小,它会影响子视图的位置和显示

view2.bounds = CGRect(x: -40, y: -20, width: 200, height: 200)

view2.backgroundColor = UIColor.yellowColor()

self.view.addSubview(view2)

let viewSub = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))

viewSub.backgroundColor = UIColor.blueColor()

view2.addSubview(viewSub)

8. 视图的基本操作

override func viewDidLoad() {

super.viewDidLoad()

// Do any additional setup after loading the view, typically from a nib.

//视图的添加与删除、切换视图在父视图中的层次

let rect = CGRect(x: 30, y: 50, width: 200, height: 200)

let view = UIView(frame: rect)

view.backgroundColor = UIColor.brownColor()

self.view.addSubview(view)

let btAdd = UIButton(frame: CGRect(x: 30, y: 350, width: 80, height: 30))

btAdd.backgroundColor = UIColor.grayColor()

btAdd.setTitle("Add", forState: UIControlState())

btAdd.addTarget(self, action: #selector(ViewController.addView(_:)), forControlEvents: UIControlEvents.TouchUpInside)

self.view.addSubview(btAdd);

let btBack = UIButton(frame: CGRect(x: 120, y: 350, width: 80, height: 30))

btBack.backgroundColor = UIColor.grayColor()

btBack.setTitle("Switch", forState: UIControlState())

btBack.addTarget(self, action: #selector(ViewController.bringViewBack(_:)), forControlEvents:UIControlEventTouchDragExit)

self.view.addSubview(btBack);

let btRemove = UIButton(frame: CGRect(x: 210, y: 350, width: 80, height: 30))

btRemove.backgroundColor = UIColor.grayColor()

btRemove.setTitle("Remove", forState: UIControlState())

btRemove.addTarget(self, action: #selector(ViewController.removeView(_:)), forControlEvents:UIControlEventTouchDragExit)

self.view.addSubview(btRemove);

}

func addView(_ sender:UIButton)

{

let rect = CGRect(x: 60, y: 90, width: 200, height: 200)

let view = UIView(frame: rect)

view.backgroundColor = UIColor.purpleColor()

view.tag = 1;

self.view.addSubview(view)

}

func bringViewBack(_sender:UIButton)

{

let view = self.view.viewWithTag(1)

self.view.sendSubviewToBack(view!)

}

func removeFromView(_sender:UIButton)

{

let view = self.view.viewWithTag(1)

view?.removeFromSuperview();

}

iOS - SWift3 & XCode8的更多相关文章

  1. iOS开发 Xcode8中遇到的问题及改动

      iOS开发 Xcode8中遇到的问题及改动 新版本发布总会有很多坑,也会有很多改动. 一个一个填吧... 一.遇到的问题 1.权限以及相关设置 iOS10系统下调用系统相册.相机功能,或者苹果健康 ...

  2. iOS开发——基础篇——iOS开发 Xcode8中遇到的问题及改动

      iOS开发 Xcode8中遇到的问题及改动 新版本发布总会有很多坑,也会有很多改动. 一个一个填吧... 一.遇到的问题 1.权限以及相关设置 iOS10系统下调用系统相册.相机功能,或者苹果健康 ...

  3. 【iOS】Xcode8+Swift3 纯代码模式实现 UICollectionView

    开发环境 macOS Sierra 10.12.Xcode 8.0,如下图所示: 总体思路 1.建立空白的storyboard用于呈现列表 2.实现自定义单个单元格(继承自:UICollectionV ...

  4. iOS之Xcode8 Auto Layout新特性

    目录 1.Incrementally Adopting Auto Layout 2.Design and Runtime Constraints 3.NSGridView 4.Layout Feedb ...

  5. Unity5.x发布IOS项目Xcode8免签证调试发布教程

    https://www.jianshu.com/p/b0fb49fbcc14 最近尝试发布一下IOS项目,发现现在发布已经简单很多了,不需要开发者账户也能简单快捷进行真机调试. 调试: 1.准备工作 ...

  6. 【转】Unity5.x发布IOS项目Xcode8免签证调试发布教程

    http://www.jianshu.com/p/b0fb49fbcc14 最近尝试发布一下IOS项目,发现现在发布已经简单很多了,不需要开发者账户也能简单快捷进行真机调试. 调试: 1.准备工作①硬 ...

  7. [iOS开发]Xcode8兼容iOS7以及低版本Xcode调试高版本iOS系统

    现在的项目一般都要兼容iOS7系统,同时也要兼容iOS10,在Xcode8上面,默认情况下无法调试iOS7,因为缺乏调试iOS7需要的配置文件.同时在低版本的Xcode上面(8以下),也无法调试iOS ...

  8. iOS Swift3.0 OC 数据储存--归档

    一.Swift 3.0 1.model class userModel: NSObject,NSCoding { var account: String = "" var regm ...

  9. iOS开发Xcode8需要注意的那些坑

    现在在苹果的官网上,我们已经可以下载到Xcode8的GM版本了,加上9.14日凌晨,苹果就要正式推出iOS10系统的推送了,在此之际,iOS10的适配已经迫在眉睫啦,不知道Xcode8 beat版本, ...

随机推荐

  1. Android C2DM学习 - 云端推送

    一.基础知识 当我们开发需要和服务器交互的应用程序时,基本上都需要获取服务器端的数据,比如<地震及时通>就需要及时获取服务器上最新的地震信息.要获取服务器上不定时更新的信息一般来说有两种方 ...

  2. <<SAP内存计算——HANA>> 书评

    <SAP内存计算——HANA>又是一本在地铁里读完的书,最近阅读量大增,都是托了地铁的福了. 一年多以前就在ITPUB里发过帖子问“SAP HANA归根揭底到底是什么?”,那时通过一些网络 ...

  3. 《TCP/IP具体解释卷2:实现》笔记--IP多播

    D类IP地址(224.0.0.0到239.255.255.255)不识别互联网内的单个接口,但识别接口组,被称为多播组. 单个网络上的组成员利用IGMP协议在系统之间通信. 多播路由器用多播选录协议. ...

  4. iOS开发——实用OC篇&多种定时器详细介绍

    多种定时器详细介绍   在软件开发过程中,我们常常需要在某个时间后执行某个方法,或者是按照某个周期一直执行某个方法.在这个时候,我们就需要用到定时器. 然而,在iOS中有很多方法完成以上的任务,到底有 ...

  5. jquery动态生成css样式表

    $(function(){     var a=new Date().getTime();// 实时加载,目的是清除缓存    $("head").append('<link ...

  6. Java再学习——sleep(), wait(), notify(), notifyAll()

    首先一点就是Thread.sleep(long millis)方法是Thread类的静态方法,其他三个wait(), notify()和notifyAll()都是Object类的方法. sleep(l ...

  7. iOS (UIButton封装)仿糯米首页缩放“按钮”效果

    前言 过年期间,少不了各种聚会,当下聚会大多数情况下自然是团购,然后就是用各种APP...使用度娘糯米时(不是广告,不是广告,不是广告!),偶然注意到了它的首页中一个有意思的效果,就是那些“按钮”点击 ...

  8. ScrollView嵌套recyclerView出现的滑动问题

    记得以前在解决scrollView与ListView嵌套问题时,那个时候是自定义了listView去测量listView高度,今天项目中刚 好碰到了要用recycerView,同样也是嵌套在scrol ...

  9. ionic实现双击返回键退出软件

    1.首先要安装cordova插件:插件地址:cordova plugin add https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git ...

  10. Windows 7 无线网络故障

    朋友打电话来问为何他的PC不能连接到家里的无线网络,而手机等其他设备都可以?相互交谈之中,我问如下几个问题: 是否可以搜索到其他无线网络? 答:是.(想确实无线网卡工作是否正常) 新的手机是否可以连接 ...