Skip to content

Instantly share code, notes, and snippets.

@RustemAqtau
Created April 11, 2020 18:13
Show Gist options
  • Save RustemAqtau/185e547a4c23ac087a9f2d3b95acad4a to your computer and use it in GitHub Desktop.
Save RustemAqtau/185e547a4c23ac087a9f2d3b95acad4a to your computer and use it in GitHub Desktop.
Factory for reuse Swift UIKIT
struct UIFactory {
struct Utility {
static func box(color: NSColor = .white, superview: NSView? = nil) -> NSBox {
let box = NSBox(frame: .zero)
box.boxType = .custom
box.borderColor = .clear
box.titlePosition = .noTitle
box.fillColor = color
superview?.addSubview(box)
return box
}
static func popupButton(itemTitles: [String], superview: NSView? = nil) -> NSPopUpButton {
let popup = NSPopUpButton(frame: .zero)
popup.removeAllItems()
popup.addItems(withTitles: itemTitles)
popup.selectItem(at: 0)
popup.resetTitleColor()
superview?.addSubview(popup)
return popup
}
static func dot(color: NSColor, diameter: CGFloat = 6, superview: NSView? = nil) -> MRView {
let view = NSView(superview: superview)
view.layer!.cornerRadius = diameter * 0.5
view.backgroundColor = color
constrain(view) { view in
view.width == diameter
view.height == view.width
}
return view
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment