3 Commits

Author SHA1 Message Date
Oskar Groth 32f6a6d397 Pod 2017-04-10 09:57:24 +02:00
Oskar Groth 0523e2578c SetOn 2017-04-10 09:56:21 +02:00
Oskar Groth 2e199eed4d Initial coloring, IBVar reloads 2017-04-08 14:22:18 +02:00
5 changed files with 51 additions and 12 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = 'OGSwitch'
s.version = '1.4'
s.version = '1.7'
s.summary = 'Switch with icon'
s.homepage = 'https://github.com/OskarGroth/OGSwitch'
s.license = {
@@ -10,12 +10,12 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "OGSwitch/OGSwitch.swift"
timestampString = "509792812.217359"
timestampString = "513346877.889494"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "69"
endingLineNumber = "69"
landmarkName = "setupIcon()"
startingLineNumber = "77"
endingLineNumber = "77"
landmarkName = "init(coder:)"
landmarkType = "7">
<Locations>
<Location
+42 -7
View File
@@ -11,14 +11,42 @@ import QuartzCore
public class OGSwitch : NSControl {
@IBInspectable public var tintColor: NSColor = NSColor(calibratedRed:0.27, green: 0.86, blue: 0.36, alpha: 1.0)
@IBInspectable public var knobBackgroundColor: NSColor = NSColor(calibratedWhite:1.0, alpha: 1.0)
@IBInspectable public var disabledBorderColor: NSColor = NSColor(calibratedWhite: 0.0, alpha: 0.2)
@IBInspectable public var disabledBackgroundColor: NSColor = NSColor.clear
@IBInspectable public var inactiveBackgroundColor: NSColor = NSColor(calibratedWhite: 0.0, alpha:0.3)
@IBInspectable public var tintColor: NSColor = NSColor(calibratedRed:0.27, green: 0.86, blue: 0.36, alpha: 1.0) {
didSet {
reloadLayer()
}
}
@IBInspectable public var knobBackgroundColor: NSColor = NSColor(calibratedWhite:1.0, alpha: 1.0) {
didSet {
reloadLayer()
}
}
@IBInspectable public var disabledBorderColor: NSColor = NSColor(calibratedWhite: 0.0, alpha: 0.2) {
didSet {
reloadLayer()
}
}
@IBInspectable public var disabledBackgroundColor: NSColor = NSColor.clear {
didSet {
reloadLayer()
}
}
@IBInspectable public var inactiveBackgroundColor: NSColor = NSColor(calibratedWhite: 0.0, alpha:0.3) {
didSet {
reloadLayer()
}
}
@IBInspectable public var animationDuration: TimeInterval = 0.4
@IBInspectable public var inactiveIcon: NSImage?
@IBInspectable public var activeIcon: NSImage?
@IBInspectable public var inactiveIcon: NSImage? {
didSet {
reloadLayer()
}
}
@IBInspectable public var activeIcon: NSImage? {
didSet {
reloadLayer()
}
}
@IBInspectable public var ignoreRatio: Bool = false
let kBorderLineWidth:CGFloat = 1.0
@@ -65,6 +93,13 @@ public class OGSwitch : NSControl {
setupIcon()
}
public func setOn(isOn: Bool, animated: Bool) {
if self.isOn != isOn {
self.isOn = isOn
reloadLayerAnimated(animated: animated)
}
}
internal func setupIcon() {
guard let icon = inactiveIcon, let bounds = knobLayer?.bounds else {
return
+1
View File
@@ -30,6 +30,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
@objc func timer() {
print("Trim is after now: \(switchButton.isOn)")
switchButton.setOn(isOn: !switchButton.isOn, animated: false)
}
}
+3
View File
@@ -697,6 +697,9 @@
<userDefinedRuntimeAttribute type="image" keyPath="inactiveIcon" value="NSEnterFullScreenTemplate"/>
<userDefinedRuntimeAttribute type="image" keyPath="activeIcon" value="NSBookmarksTemplate"/>
<userDefinedRuntimeAttribute type="boolean" keyPath="ignoreRatio" value="YES"/>
<userDefinedRuntimeAttribute type="color" keyPath="disabledBackgroundColor">
<color key="value" red="1" green="0.40000000600000002" blue="0.40000000600000002" alpha="1" colorSpace="calibratedRGB"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<action selector="switchPress:" target="Voe-Tx-rLC" id="Mqi-G6-fmv"/>