mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
fix: fixed switch buttons visibility on macOS 10.13 (#559)
This commit is contained in:
@@ -226,36 +226,41 @@ public extension NSView {
|
||||
}
|
||||
|
||||
func toggleTitleRow(frame: NSRect, title: String, action: Selector, state: Bool) -> NSView {
|
||||
let row: NSView = NSView(frame: frame)
|
||||
let row: NSStackView = NSStackView(frame: frame)
|
||||
row.orientation = .horizontal
|
||||
row.spacing = 0
|
||||
row.distribution = .fillProportionally
|
||||
|
||||
let title: NSTextField = LabelField(frame: NSRect(x: 0, y: 0, width: 0, height: 0), title)
|
||||
title.font = NSFont.systemFont(ofSize: 13, weight: .light)
|
||||
title.textColor = .textColor
|
||||
|
||||
let state: NSControl.StateValue = state ? .on : .off
|
||||
|
||||
let rowTitle: NSTextField = LabelField(frame: NSRect(x: 0, y: (row.frame.height - 16)/2, width: row.frame.width - 52, height: 17), title)
|
||||
rowTitle.font = NSFont.systemFont(ofSize: 13, weight: .light)
|
||||
rowTitle.textColor = .textColor
|
||||
|
||||
var toggle: NSControl = NSControl()
|
||||
if #available(OSX 10.15, *) {
|
||||
let switchButton = NSSwitch(frame: NSRect(x: row.frame.width - 50, y: 0, width: 50, height: row.frame.height))
|
||||
let switchButton = NSSwitch(frame: NSRect(x: 0, y: 0, width: 50, height: row.frame.height))
|
||||
switchButton.state = state
|
||||
switchButton.action = action
|
||||
switchButton.target = self
|
||||
|
||||
toggle = switchButton
|
||||
} else {
|
||||
let button: NSButton = NSButton(frame: NSRect(x: row.frame.width - 30, y: 0, width: 30, height: row.frame.height))
|
||||
let button: NSButton = NSButton(frame: NSRect(x: 0, y: 0, width: 20, height: row.frame.height))
|
||||
button.widthAnchor.constraint(equalToConstant: button.bounds.width).isActive = true
|
||||
button.setButtonType(.switch)
|
||||
button.state = state
|
||||
button.title = ""
|
||||
button.action = action
|
||||
button.isBordered = false
|
||||
button.isTransparent = true
|
||||
button.isTransparent = false
|
||||
button.target = self
|
||||
button.wantsLayer = true
|
||||
|
||||
toggle = button
|
||||
}
|
||||
|
||||
row.addSubview(toggle)
|
||||
row.addSubview(rowTitle)
|
||||
row.addArrangedSubview(title)
|
||||
row.addArrangedSubview(toggle)
|
||||
|
||||
row.widthAnchor.constraint(equalToConstant: row.bounds.width).isActive = true
|
||||
row.heightAnchor.constraint(equalToConstant: row.bounds.height).isActive = true
|
||||
|
||||
Reference in New Issue
Block a user