Calle it: CustomViewXib.xib
open the file with IB and add your graphic
create a new CustomView.swift
Code: Select all
import UIKit
class CustomView: UIView {
class func instanceFromNib() -> UIView {
return UINib(nibName: "CustomViewXib", bundle: nil).instantiateWithOwner(nil, options: nil)[0] as! UIView
}
}
In the CustomViewXib.xib, Identity Inspector, in the Class top field, set CustomView (from the Class in the swift file)
Now, add the custom view programmatically:
in the ViewController.swift add:
Code: Select all
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let mView = CustomView.instanceFromNib()
view.addSubview(mView)
}