Created
April 11, 2020 18:13
-
-
Save RustemAqtau/185e547a4c23ac087a9f2d3b95acad4a to your computer and use it in GitHub Desktop.
Factory for reuse Swift UIKIT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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