This document discusses using @IBDesignable to design user interfaces in Interface Builder. It explains that @IBDesignable allows custom UI classes to be rendered in Interface Builder by compiling code when a storyboard or XIB file is opened. It also describes how to define an @IBDesignable class to add a cornerRadius property to a round button that updates its layer in draw(), and discusses some limitations of using @IBDesignable like increased compilation time.
8. Interface Builder
• Interface Builder allows developers to create interfaces
for applications using a graphical user interface.
• The resulting interface is stored as a .nib /.xib file, short for NeXT
Interface Builder.
• To build an interface, a developer simply drags interface objects
from the palette onto a windo.
• In this way all initialization is done before runtime, both improving
performance and streamlining the development process.
• Interface designers could ship nib files to developers, who would
then drop them into their projects.
22. Why / What bother
• It Will Compile all the stuff in Module code base
• Every time you try to open a .storyboard / .xib file
• Cocoa Touch Framework will limit code base
23.
24. @IBDesignable public class RoundButton: UIButton {
@IBInspectable public var cornerRadius:CGFloat = 0
override public func draw(_ rect: CGRect) {
super.draw(rect)
clipsToBounds = cornerRadius > 0
layer.cornerRadius = cornerRadius
}
}
25. @IBDesignable public class RoundButton: UIButton {
@IBInspectable public var cornerRadius:CGFloat = 0
override public func draw(_ rect: CGRect) {
super.draw(rect)
clipsToBounds = cornerRadius > 0
layer.cornerRadius = cornerRadius
}
}