===================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.main.loadNibNamed("LYBMyHeaderView", owner: nil, options: nil)?.last as! LYBMyHeaderView
或者
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)