iOS 10 开发第一季 ③中级篇

iOS 10 开发第一季的第三篇

默认教学计划
1377人加入学习
(8人评价)
价格 免费
教学计划

var areas: [Area] = [

        Area(name: "闵行区莘庄镇", province: "上海", part: "华东", image: "xinzhuang", isVisited: false),

        Area(name: "兰州市七里河区", province: "甘肃", part: "西北", image: "qilihe", isVisited: false),

        Area(name: "三明市尤溪县", province: "福建", part: "东南", image: "youxi", isVisited: false),

        Area(name: "西宁城西区", province: "青海", part: "西北", image: "chengxi", isVisited: false),

        Area(name: "广州白云区", province: "广东", part: "华南", image: "baiyun", isVisited: false),

        Area(name: "闽侯县上街镇", province: "福建", part: "东南", image: "shangjie", isVisited: false),

        Area(name: "哈尔滨市南岗区", province: "黑龙江", part: "东北", image: "nangang", isVisited: false),

        Area(name: "临汾市尧都区", province: "山西", part: "华北", image: "yaodu", isVisited: false),

        Area(name: "成都市武侯区", province: "四川", part: "西南", image: "wuhou", isVisited: false),

        Area(name: "汕头市金平区", province: "广东", part: "华南", image: "jinping", isVisited: false),

        Area(name: "长沙市芙蓉区", province: "湖南", part: "华中", image: "furong", isVisited: false)

    ]

[展开全文]

在 Swift 4.0 中,NSFontAttributeName 和 NSForegroundColorAttributeName 全部并入 NSAtrributedStringKey 中,分别是 .font 和 .foregroundColor

[展开全文]

额,这一块感觉小波老师自己都乱了

[展开全文]

返向转场

DetailTableViewController.swift

@IBAction func close(segue:UIStoryboardSegue) {

let nextVC = segue.source as! ReviewVC 

if let rating = nextVC.rating {

  self.area.rating = rating

 self.ratingBtn.setImage(UIImage(named:rating),for:.normal)

}

}

[展开全文]

content Hugging Priority 

 

[展开全文]

启用自适应+约束

 

shift+ top Space

      + bottom Space 

加约束

[展开全文]

 选择完图片后做约束!

问题:图片保存完后,如何新增进沙盒?

 

[展开全文]

调用系统相册
info.plist 加入2项隐私权限Privacy

UIImagePickerController

单元格选择事件

didSelectRowAt {

if indexPath.row == 0 {

// 相册是否可用
guard UIImagePickerController.isSourceTypeAvailable(.photoLiberary) else {

return }

let picker = UIImagePickerController
picker.allaowsEditing = false 
picker.sourceType = .photoLibrary

// 实现自己代理
picker.delegate = self 
self.present(picker,animated:ture,completion:nil)
}

}

加入2个协议

UITableViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate

// 触发方法

func imagePickerController (_ picker:UIImagePickerController,didFinishPickingMediaWithInfo info:[String:Any]){

// code here 

coverImageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage
coverImageView.contentMode = .scaleAspectFill
coverImageview.clipsToBounds = true
// 视图退场
dismiss(animated:true,completion:nil)
 

 

}

[展开全文]

反向转场

须在要退回的controller加入参数类型为UIStoryboard 修饰符为IBAction的方法

一、即在父ViewController(方法名随便起)

@IBAction func unwindBackHome(segue:UIStoryboardSegue){

}

二、在Details中的Cancel按钮,拉线到Exit出口

 

正向传值 表格选中行

override func prepare(for segue:UIStoryboardSegue,sender:Any?){

if segue.identifier == "showDetail" {

let dest =  segue.destination as! DetailTableViewController 

dest.area = areas[tableView.indexPathForSelectedRow!.row]

}

}

[展开全文]
布袋 · 2017-06-05 · 2.添加转场 0

DetalisTableViewControll里的 DetailsTableViewCell

 

cellForRowAt

 

let cell = tableView.dequeueReusableCell(withIdentifier:"",for:indexPath) as! DetailsTableViewCell

switch indexPath.row {

case 0:

cell.filedLabel.text = "地名"

cell.valueLabel.text = area.name

case 1:

case 2:

case 3:

default:break

 

}

return cell

[展开全文]

 DetailsTableViewController

中的ImageView是在Cell的上方,

不包含在cell里面!

[展开全文]

二、label的Lines 的行数,调为 0 

才可和 tableView.rowHeight 相匹配

 

三、做好约束 

top bottom 的 space 的距离为 0 

 

左 右 上 下

Trailing Space 

Leading Space

Top Space

Bottom Space 

注意:ImageView不能设约束

[展开全文]

单元格 自适应单元格

tableView.estimatedRowHeight = 50

tableView.rowHeight = UITableViewAutomaticDemension 

 

[展开全文]

没有导航条的情况下设置状态条

override var preferredStatusBarStyle:UIStatusBarStyle {

return .lightContent

}

或者 Application 

 

UIApplication.shared.statusBarStyle = .lightContent

 

 

[展开全文]

返回按钮只保留Arrow

self.navigationItem.backBarButtonItem = 

UIBarButtonItem(title:"",style:.plain,target:nil,action:nil)

[展开全文]

***** 自动布局表格重点 *****

cell相对于contentView做约束


Shift 把字段同时做约束

优先级:

Content Huggin Priority 

值越大,越不会被拉伸

 

字段 拉线到值 

Equal Widths Multiplier 0.5 

*****

建立单元格控制器

*****

class:DetailTableViewCell 

Subclass of:UITableViewCell

[展开全文]

图像填充模式!

Aspect to Fill

clips to bounds!

[展开全文]

授课教师

Swift小菜

课程特色

视频(28)
下载资料(3)