Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 1. 新建 MyView.xib 文件
- // 2. 新建 MyView 类
- // 3. 增加如下代码
- class MyView: UIView {
- override init(frame: CGRect) {
- super.init(frame: frame)
- self.commomInit()
- }
- required init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
- self.commomInit()
- }
- // TODO: 将Xib的FileOwner设置该View
- func commomInit() {
- let view = Bundle.main.loadNibNamed("MyView", owner: self, options: nil)?.first as! UIView
- self.addSubview(view)
- view.frame = self.bounds
- }
- }
- // 4. 将 MyView.xib的FileOwner设置为MyView
- // 使用
- let v = MyView(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: 50))
Add Comment
Please, Sign In to add comment