Issue #297
let button = NSButton()
button.wantsLayer = true
button.isBordered = false
button.setButtonType(.momentaryChange)
button.attributedTitle = NSAttributedString(
string: "Click me",
attributes: [
NSAttributedString.Key.foregroundColor: NSColor.white,
NSAttributedString.Key.font: NSFont.labelFont(ofSize: 13)
]
button.layer?.backgroundColor = NSColor.orange.cgColor
button.layer?.cornerRadius = 12
activate(
button.anchor.height.equal.to(32),
button.anchor.width.equal.to(100)
)
To make it have native rounded rect
button.imageScaling = .scaleProportionallyDown
button.setButtonType(.momentaryPushIn)
button.bezelStyle = .rounded
button.isBordered = true
import AppKit
import Omnia
extension NSButton {
func style(imageName: String) {
image = NSImage(named: NSImage.Name(imageName))
isBordered = false
imageScaling = .scaleProportionallyDown
}
func styleAction(title: String) {
attributedTitle = NSAttributedString(string: title, attributes: [
NSAttributedString.Key.foregroundColor: NSColor(hex: "008B80"),
NSAttributedString.Key.font: NSFont.boldSystemFont(ofSize: 13)
])
isBordered = false
setButtonType(.momentaryChange)
}
}