swift之xib的使用、從xib獲取view和控制器、storyboard獲取控制器
===================xib建立View
===========
import UIKit
class LYBMyHeaderView: UIView {
override func awakeFromNib() {
super.awakeFromNib()
backgroundColor=UIColor.red
self.frame=CGRect(x:0,y:0,width:WIDTH,height:200)
}
}
===================使用:
let v:LYBMyHeaderView=Bundle
或者
let nib = UINib(nibName: "LYBMyHeaderView", bundle: nil)
let v = nib.instantiate(withOwner: nil, options: nil)[0] as! LYBMyHeaderView
======================xib建立控制器
使用:
let infovc=LYBInfoVC
self.navigationController?.pushViewController(infovc, animated: true)
=====================storyBoard建立控制器
使用:let sb=UIStoryboard.init(name: "LYIn", bundle: nil)
let infovc = sb.instantiateInitialViewController()as! LYBInfoVC
self.navigationController?.pushViewController(infovc, animated: true