创建: 2018/04/19

完成: 2018/04/20

View的创建
 创建  storyboard上操作
 与代码连接

● 目的: 通过代码控制view

● 按住option拖动

View的坐标
 view的坐标

左上为原点,

往右+x, x为width

往下+y, y为height

CGRect

处理x, y, width, height的构造体

● 生成:

CGRect(x: x, y: y, width: width, height: height)

● 属性

minX

midX

maxX

 

minY

midY

maxY

 
   
 CGPoint

处理坐标x, y的构造体

● 生成:

CGPoint(x: x, y: y)
 CGSize

处理长宽width, height的构造体

● 生成:

CGSize(width: width, height: height)
 属性
 frame  表示在父view中位置的CGRect
 bounds

以自己为中心的CGRect

● 原点自己左上

   
在程序里创建View
   addSubView(view: UIView)

let viewByCode = UIView.init(frame: CGRect.init(x: , y: , width: , height: ))
viewByCode.backgroundColor = UIColor.green
topAreaView.addSubview(viewByCode)
   
UIView
   所有UI都是UIView的子类
 

● 设定坐标          CGRect

● 设定border

● 增加subView    addSubView

● 下面的

 属性

contentMode

  对应项目条: Content Mode
 isUserInteractionEnabled

是否接受Event

对应项目条: User Interaction Enabled

 alpha

不透明度

对应项目条: alpha

 backgroundColor

背景色

对应项目条: Background

 isHidden

是否隐藏

对应项目条: Hidden

 clipsToBounds

超过边界的是否删除

效果相当于css的overflow: hidden

对应项目条: Clip to Bounds

 方法
 removeFromSuperView  从所属的super view里删除自己
 bringSubView(toFront:)  把指定的sub view移到最前面
 sizeToFit  根据内容调整大小
   
   
   
UIImageView
   ● 用于展示图片
 content mode

对应项目条: content mode

 Scale to Fill  伸缩图片填满view
 Aspect Fit  保持宽高比放入view
 Aspect Fill

保持原尺寸填满view

多余部分溢出, 设置Clip to Bounds来切除溢出部分

 方位(Left, Right, ...)  靠某一边对齐, 尺寸不变
   
UIScrollView
 

UITableView, UICollectionView的父类

 设置滚动内容大小

● 通过autolayout自动设置

● contentSize属性

 带项目条的属性 
 indicatorStyle

滚动条的款式

对应项目条: Indicators

 showsHorizontalScrollIndicator

是否显示水平滚动条

对应项目条: Shows Horizontal Indicator

 showsVerticalScrollIndecator

是否显示垂直滚动条

对应项目条: Shows Vertical Indicator

 isScrollEnabled

是否可滚动

对应项目条: Scrolling Enabled

 isDirectionLockEnabled

滚动中是否固定方向

对应项目条: Direction Lock Enabled

 keyboardDismissMode

滚动时是否关闭键盘

● 内部有text field/text view是自动设为有效

对应项目条: Keyboard

 alpha

不透明度

对应项目条: Alpha

 backgroundColor

背景色

对应项目条: Background

 Hidden

是否隐藏

对应项目条: isHidden

   
 其他属性
 contentSize  滚动内容的大小
 scrollsToTop

是否触击状态栏返回最顶部

默认 true

   
   
   
 方法
 scrollRectToVisible(rect: animated:) -> Void  
   
   
   
   
UITableView
 重复利用cell

● 提高运行效率

 注册利用的cell

● 用代码注册则为代码里的状态.

也就是说storyboard上的设定全都不生效

● 不要代码注册, 直接storyboard上注册

register(cellClass: forCellReuseIdentifier:) -> Void

middleTableView.register(MiddleTableViewCell.self, forCellReuseIdentifier: "sample")
 使用注册的cell  存在的时候用存在的, 不存在则自动新建

dequeueReusableCell(withIdentifier: for: )

例:

let cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentifier, for: indexPath)
 datasource

必须继承UITableViewDataSource

分出去单独类时, 要继承NSObject

 必须的方法

设置session的行数

func tableView(_ tableView: UITableView numberOfRowsInSection section: Int) -> Int
 设置每行表示的cell

func tableView(_ tableView: UITableView cellForRowAt indexPath: IndexPath) -> UITableViewCell

● 调用时间: 生成cell, 重绘cell时(如划动时移出view的cell)

   
 其他方法
 设置section数

func numberOfSections(in tableView: UITableView) -> Int

设置section的header标题

func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?
   
   
   
   
   
   
   
   
 delegate 

必须继承UITableViewDelegate

● 分出去单独类时, 要继承NSObject

● 没有必须的方法, 可以不实现

   
   
   
   
   
   
   
   
   
UICollectionView
   和UITableView差不多

注册与

再利用cell

 注册

● 用代码注册则为代码里的状态.

也就是说storyboard上的设定全都不生效

● 不要代码注册, 直接storyboard上注册

bottomCollectionView.register(BottomCollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
 再利用

存在的时候用存在的, 不存在则自动新建

collectionView.dequeueReusableCell(withReuseIdentifier: self.reuseIdentifier!, for: indexPath)

dataSource

必须继承UICollectionViewDelegate

● 分出去单独类时, 要继承NSObject

● 没有必须的方法, 可以不实现

必须

 设置元素数

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int)
-> Int
 设置cell

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath)
-> UICollectionViewCell
   
 delegate 

必须继承UICollectionViewDelegate

● 分出去单独类时, 要继承NSObject

● 没有必须的方法, 可以不实现

   
   

iOS View的更多相关文章

  1. iOS View 模糊效果(毛玻璃)

    iOS View 模糊效果(毛玻璃)   相关资料 http://stackoverflow.com/questions/18404907/using-gpuimage-to-recreate-ios ...

  2. ios View 向上拉界面源码

    如下的资料是关于ios View 向上拉界面的代码. #pragma mark - 上升效果- (void)ToUpSide {          } - (void)moveToUpSide {   ...

  3. ios view的frame和bounds之区别(位置和大小)

    前言: 学习ios开发有一段时间了,项目也做了两个了,今天看视频,突然发现view的frame和bound两个属性,发现bound怎么也想不明白,好像饶你了死胡同里,经过一番尝试和思考,终于弄明白bo ...

  4. iOS View的Frame和bounds之区别,setbounds使用(深入探究)

    前言: 在ios开发中经常遇到两个词Frame和bounds,本文主要阐述Frame和bound的区别,尤其是bound很绕,较难理解. 一.首先,看一下公认的资料: 先看到下面的代码你肯定就明白了一 ...

  5. iOS view和viewController的生命周期

    一.ViewController的职责 对内管理与之关联的View,对外跟其他ViewController通信和协调.对于与之关联的View,ViewController总是在需要的时候才加载视图,并 ...

  6. ios View之间的切换 屏幕旋转

    6.3  View之间的切换 在上面的练习中我们通过移动组件的位置和调整组件的大小来处理横向与纵向的界面布局.但是在界面中有很多组件的时候,对每个组件都进行这样的操作确实是一个麻烦的事情.下面我们看看 ...

  7. IOS view拖拽(触摸事件)

    • iOS中的事件可以分为3大类型 触摸事件 加速计事件 远程控制事件 响应者对象 • 在iOS中不是任何对象都能处理事件,只有继承了UIResponder的对象才能接收并处理事 件.我们称之为“响应 ...

  8. IOS View编程指南笔记

    我们所示程序 对于一切IOS APP来说.我们看的的内容,都是UIView所呈现的. UIView如场景,UIWindow如舞台.UIView粉墨登场在UIWindow这个舞台上,使我们看到丰富多彩的 ...

  9. 解决 iOS View Controller Push/Pop 时的黑影

    那么如何解决这个问题呢? 实际上很简单,如果这个 ViewController 是在 TabBarViewController 的 NavigationController 上 Push/Pop 的, ...

  10. ios view改变背景图

    一般我们设置 一个view的背景  可以通过  在view上放一个imageView 来显示背景图片 这里介绍另外一种方法 可以直接通过改变view.backgroundColor的值 来达到上面的效 ...

随机推荐

  1. keras函数式编程(多任务学习,共享网络层)

    https://keras.io/zh/ https://keras.io/zh/getting-started/functional-api-guide/ https://github.com/ke ...

  2. js中有包装类,java中也有包装类

    new Number() vs Number() What is the difference between new Number() and Number()? I get that new Nu ...

  3. 阿里云OSS 图片处理api(custom)

    阿里云OSS 图片处理api(custom) 阿里云对象存储服务(Object Storage Service, 简称OSS) 学习了:https://blog.csdn.net/u014559227 ...

  4. 集成CCFlow工作流与GPM的办公系统驰骋CCOA介绍(三)

    通过组织结构能够对项目的岗位.部门.人员进行增删改操作. 加入新部门.并为新部门加入人员: 选中部门后,点击鼠标右键,能够选择加入平级部门或下属部门. 新建部门时,须要给部门设置部门编号.名称.与部门 ...

  5. mysql 安装与启动

    1.下载mysql installer 2.安装 一直点next,直到finish. 3.安装时的配置 安装完后,选择立即开始配置. 选择standard configuration 勾选安装mysq ...

  6. JSP简明教程:汇总

    原创JSP教程,简洁明了,不含废话. JSP简明教程(一):JSP简单介绍 JSP简明教程(二):JSP基本的语法 JSP简明教程(三):JSP隐含对象 JSP简明教程(四):EL表达式语言.Java ...

  7. PHP将当前目录列出来

    $d=dir("."); echo $d->path; while(false !== ($e = $d->read())) { echo "<a hr ...

  8. iOS 身份证验证

    - (void)onClickButton:(id) sender{ || tmp_txt.text.length == ) { NSString *emailRegex = @"^[0-9 ...

  9. return和exit

    return从当前函数返回而exit结束正在运行的程序 示例: [wangml@iZwz976helaylvgqok97prZ testForC]$ ./exit.test q [wangml@iZw ...

  10. 6. IO复用:select 和 poll

    select #include <sys/select.h> #include <sys/time.h> int select(int maxfdp1, fd_set *rea ...