寫在最前面:
歡迎大家關注我的個人博客:<a >博客地址</a>,這里主要是我在個人開發時候遇到的坑和挖完的坑,包括 PHP CentOS 以及 Swift 等相關只是
說實話我是一個執著于純代碼布局的人,但這有一個前提就是你在使用全代碼布局前應該如何使用storyboard布局,這樣你才能很好的使用純代碼布局,理解兩種不同的布局形式,其實底層做的都是同樣的事情。好啦話不多說上效果圖
noasis-01.gif
知識點:
- 學會使用Snapkit做純代碼的AutoLayout布局,我之前的文章有講解過
- 使用純代碼創建自定義的UITableViewCell
- 使用UITableView注冊UITableViewCell
- 使用UITableView自適應行高(>= iOS 8.0)
- 常用知識點:整理一下,我經常忘記的知識點
常用知識點
UITableView的一些簡單設置:
去掉分割線
<code>tableView.separatorStyle = .None</code>去掉點擊事件
UITableView的注冊自定義Cell方法
<pre>```Swift
private var postListCellIdentifier = "postList"
//注冊純代碼UITableViewCell時
tableView.registerClass(PostList.self, forCellReuseIdentifier: postListCellIdentifier)
//注冊基于Xib的UITableViewCell時使用
tableView.registerNib(UINib(nibName: "PostCell", bundle: nil), forCellReuseIdentifier: postListCellIdentifier)
-UITableViewCell自適應高度(iOS8.0新特性)
>UITableViewCell必須給予AutoLayout布局,最后一個UILable一定要給他一個bottom布局屬性,否則將沒辦法自適應高度(坑,勿踩)
<pre>```Swift
tableView.estimatedRowHeight = 450//MARK: 預估高度
tableView.rowHeight = UITableViewAutomaticDimension //MARK: 自適應高度
```</pre>
####clipsToBounds與maskToBounds
>如果你如下操作,如果你不加上
<pre>```Swift
let img = UIImage(named: "us.jpg")
let vImg = UIImageView()
//vImg.layer.masksToBounds = true
//vImg.clipsToBounds = true
vImg.layer.cornerRadius = 50
vImg.image = img
vImg.frame = CGRect(origin: CGPointMake(100, 100), size: CGSizeMake(100, 100))
vImg.contentMode = .ScaleAspectFill
vImg.center = view.center
self.view.addSubview(vImg)
```</pre>
- clipsToBounds:
>子視圖在父視圖之外的將被截取
- maskToBounds:
>子視圖在父視圖圖層之外的將被截取