Guest User

Untitled

a guest
Mar 19th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. // 1. 新建 MyView.xib 文件
  2. // 2. 新建 MyView 类
  3. // 3. 增加如下代码
  4. class MyView: UIView {
  5.  
  6. override init(frame: CGRect) {
  7. super.init(frame: frame)
  8. self.commomInit()
  9. }
  10.  
  11. required init?(coder aDecoder: NSCoder) {
  12. super.init(coder: aDecoder)
  13. self.commomInit()
  14. }
  15.  
  16. // TODO: 将Xib的FileOwner设置该View
  17. func commomInit() {
  18. let view = Bundle.main.loadNibNamed("MyView", owner: self, options: nil)?.first as! UIView
  19. self.addSubview(view)
  20. view.frame = self.bounds
  21. }
  22. }
  23. // 4. 将 MyView.xib的FileOwner设置为MyView
  24.  
  25. // 使用
  26. let v = MyView(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: 50))
Add Comment
Please, Sign In to add comment