Swift Tutorial 2 - Custom User Interface with xib files in Xcode 6

Paul Solt · 31K views · 2014 · 38:33

Open on YouTube

Software (other)UX & UI designtutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when answering how to load, wire up and reuse custom UIView subclasses backed by a xib file in Swift.

Recommended by 2 people across 2 different months, 2015 to 2016.

What it is

A 38-minute Swift tutorial by Paul Solt showing how to build a reusable custom UI from a .xib file in Xcode 6, using IBDesignable and IBInspectable so the view can be embedded in storyboards. The example turns an existing Sketch design into a widget.

What people said

Recommends Ragnar · 2016-04 · Stack Overflow · on “How to catch the click on the button in added XIB view (annotation)”

You have to put this code inside your viewController but your .xib file need it's own .swift file. look here [this video]

Recommends Scriptable · 2016-05 · Stack Overflow · on “Adding a UIView based on a template in swift?”

You can create re-usable views in the same way that you can create prototype cells. Just right click in your project window, add new file and select User Interface > View. create it just like you would a prototype cell. Then create a related class by adding a new swift file, link the two, create any outlets or actions you need and add any required logic. Once you are done you can just load it wherever you need it, like so self.headerView = NSBundle.mainBundle().loadNibNamed("HeaderView",owner:self,options:nil) as! HeaderView You would likely need to pass in some required information, or setup the views frame or constraints. I found a [this video] which should help guide you through the process. I

Cites htzfun · 2015-08 · Stack Overflow · on “How to create view programatically with .xib?”

I got a simple idea - suppose we have singletone object that works similar to local notifications - when it's called it should show message view on the current window, wherever user is now. Message view is contained in .xib and got next code @IBDesignable class MessageView : UIView { var view: UIView! var nibName: String = "MessageView" @IBOutlet weak var messageLabel: UILabel? @IBOutlet weak var closeButton: UIButton? @IBInspectable var message : String? { get { return messageLabel?.text } set { messageLabel?.text = newValue } } @IBInspectable var type : MessageType = .Info // init override init(frame: CGRect) { super.init(frame: frame) setup() } required init(coder aDecoder: NSCoder) { //