Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 35b0d46d8e | |||
| 047205a881 | |||
| ed64989887 | |||
| a4e1d06b19 | |||
| 79209bca05 | |||
| 2004091f18 | |||
| be0bd0211b | |||
| 3f6129964e | |||
| 352f7c8ad2 | |||
| 52781c2335 | |||
| 6adaab83d6 | |||
| 5d549ab629 | |||
| c54689bccc | |||
| 5ddc45e132 | |||
| 9bc2acc5f4 | |||
| d103720de4 | |||
| 09cd2cd79c |
@@ -35,8 +35,6 @@
|
||||
750F2E511E5D2D7200C20E79 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
|
||||
750F2E531E5D2D7200C20E79 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
75256FE120FA5ABC00ED6782 /* OGSwitch.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = OGSwitch.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
7553A35020F5045900EEA571 /* OGSwitch.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OGSwitch.h; sourceTree = "<group>"; };
|
||||
7553A35120F5045900EEA571 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@@ -55,7 +53,6 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
750F2E4B1E5D2D7100C20E79 /* OGSwitchDemo */,
|
||||
7553A34F20F5045900EEA571 /* OGSwitch */,
|
||||
750F2E3A1E5D2CD000C20E79 /* Products */,
|
||||
75256FE020FA5ABC00ED6782 /* Frameworks */,
|
||||
);
|
||||
@@ -88,15 +85,6 @@
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
7553A34F20F5045900EEA571 /* OGSwitch */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
7553A35020F5045900EEA571 /* OGSwitch.h */,
|
||||
7553A35120F5045900EEA571 /* Info.plist */,
|
||||
);
|
||||
path = OGSwitch;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
Pod::Spec.new do |s|
|
||||
|
||||
s.name = 'OGSwitch'
|
||||
s.version = '1.0'
|
||||
s.summary = 'Switch Control for macOS'
|
||||
s.homepage = 'https://github.com/OskarGroth/OGSwitch'
|
||||
s.license = {
|
||||
:type => 'MIT',
|
||||
:file => 'LICENSE'
|
||||
}
|
||||
s.author = {
|
||||
'Oskar Groth' => 'oskar@cindori.org'
|
||||
}
|
||||
s.source = {
|
||||
:git => 'https://github.com/OskarGroth/OGSwitch.git',
|
||||
:tag => s.version.to_s
|
||||
}
|
||||
s.platform = :osx, '10.9'
|
||||
s.source_files = 'OGSwitch/OGSwitch.{swift}'
|
||||
s.requires_arc = true
|
||||
s.screenshot = "https://raw.githubusercontent.com/OskarGroth/OGSwitch/master/screenshot.jpg"
|
||||
s.social_media_url = "https://twitter.com/cindoriapps"
|
||||
|
||||
end
|
||||
BIN
Binary file not shown.
@@ -7,9 +7,9 @@
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
75256FD820FA5A0E00ED6782 /* OGSwitch.h in Headers */ = {isa = PBXBuildFile; fileRef = 75256FD620FA5A0E00ED6782 /* OGSwitch.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
75256FDF20FA5A3E00ED6782 /* OGSwitch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75256FDE20FA5A3E00ED6782 /* OGSwitch.swift */; };
|
||||
753FF19F20FA621C00DFA33E /* OGSwitch.swift in Headers */ = {isa = PBXBuildFile; fileRef = 75256FDE20FA5A3E00ED6782 /* OGSwitch.swift */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
753FF1A520FA64B500DFA33E /* OGSwitch.swift in Headers */ = {isa = PBXBuildFile; fileRef = 75256FDE20FA5A3E00ED6782 /* OGSwitch.swift */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
753FF1A620FA64D200DFA33E /* OGSwitch.h in Headers */ = {isa = PBXBuildFile; fileRef = 75256FD620FA5A0E00ED6782 /* OGSwitch.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
@@ -63,8 +63,8 @@
|
||||
isa = PBXHeadersBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
75256FD820FA5A0E00ED6782 /* OGSwitch.h in Headers */,
|
||||
753FF19F20FA621C00DFA33E /* OGSwitch.swift in Headers */,
|
||||
753FF1A620FA64D200DFA33E /* OGSwitch.h in Headers */,
|
||||
753FF1A520FA64B500DFA33E /* OGSwitch.swift in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -13,7 +13,3 @@ FOUNDATION_EXPORT double OGSwitchVersionNumber;
|
||||
|
||||
//! Project version string for OGSwitch.
|
||||
FOUNDATION_EXPORT const unsigned char OGSwitchVersionString[];
|
||||
|
||||
// In this header, you should import all the public headers of your framework using statements like #import <OGSwitch/PublicHeader.h>
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,26 @@ import QuartzCore
|
||||
|
||||
//Can not be NSControl due to 10.9 issues: https://github.com/iluuu1994/ITSwitch/issues/21
|
||||
|
||||
public class OGSwitch : NSView {
|
||||
@IBDesignable public class OGSwitch: NSControl {
|
||||
|
||||
public enum Size {
|
||||
|
||||
case small
|
||||
case medium
|
||||
case large
|
||||
|
||||
public var size: CGSize {
|
||||
switch self {
|
||||
case .small:
|
||||
return CGSize(width: 46, height: 28)
|
||||
case .medium:
|
||||
return CGSize(width: 56, height: 34)
|
||||
case .large:
|
||||
return CGSize(width: 69, height: 41)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@IBInspectable public var tintColor: NSColor = NSColor(calibratedRed:0.27, green: 0.86, blue: 0.36, alpha: 1.0) {
|
||||
didSet {
|
||||
@@ -49,16 +68,24 @@ public class OGSwitch : NSView {
|
||||
reloadLayer()
|
||||
}
|
||||
}
|
||||
@IBInspectable public var ignoreRatio: Bool = false
|
||||
@IBInspectable public var ignoreRatio: Bool = true {
|
||||
didSet {
|
||||
reloadLayer()
|
||||
}
|
||||
}
|
||||
override public var isEnabled: Bool {
|
||||
didSet {
|
||||
reloadLayerAnimated(animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
lazy var kBorderLineWidth: CGFloat = bounds.height*(2/31)
|
||||
|
||||
let kBorderLineWidth:CGFloat = 1.0
|
||||
let kGoldenRatio:CGFloat = 1.6180339875
|
||||
let kDecreasedGoldenRatio:CGFloat = 1.38
|
||||
let kEnabledOpacity:Float = 1.0
|
||||
let kDisabledOpacity:Float = 0.5
|
||||
var dragEvents = 0
|
||||
@objc public var action: Selector?
|
||||
@objc public var target: AnyObject?
|
||||
public var isOn:Bool = false
|
||||
public var isActive:Bool = false
|
||||
public var hasDragged:Bool = false
|
||||
@@ -69,11 +96,6 @@ public class OGSwitch : NSView {
|
||||
public var knobInsideLayer: CALayer?
|
||||
public var iconLayer = CALayer()
|
||||
public var lockInteraction: Bool = false
|
||||
public var isEnabled: Bool = true {
|
||||
didSet {
|
||||
reloadLayerAnimated(animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
override public var acceptsFirstResponder: Bool {
|
||||
get {
|
||||
@@ -86,23 +108,23 @@ public class OGSwitch : NSView {
|
||||
setup()
|
||||
}
|
||||
|
||||
override init(frame:NSRect) {
|
||||
convenience public init(size: CGSize) {
|
||||
self.init(frame: NSRect(origin: .zero, size: size))
|
||||
}
|
||||
|
||||
override public init(frame:NSRect) {
|
||||
super.init(frame: frame);
|
||||
setup()
|
||||
}
|
||||
|
||||
override public func awakeFromNib() {
|
||||
super.awakeFromNib()
|
||||
reloadLayerSize()
|
||||
reloadLayer()
|
||||
setupIcon()
|
||||
}
|
||||
|
||||
internal func setup() {
|
||||
isEnabled = true
|
||||
setupLayers()
|
||||
reloadLayerSize()
|
||||
setupIcon()
|
||||
reloadLayer()
|
||||
}
|
||||
|
||||
|
||||
public func setOn(isOn: Bool, animated: Bool) {
|
||||
if self.isOn != isOn {
|
||||
self.isOn = isOn
|
||||
@@ -149,9 +171,9 @@ public class OGSwitch : NSView {
|
||||
knobLayer!.autoresizingMask = CAAutoresizingMask.layerHeightSizable
|
||||
knobLayer!.backgroundColor = knobBackgroundColor.cgColor
|
||||
knobLayer!.shadowColor = NSColor.black.cgColor
|
||||
knobLayer!.shadowOffset = CGSize(width:0.0, height:-2.0)
|
||||
knobLayer!.shadowRadius = 1.0
|
||||
knobLayer!.shadowOpacity = 0.3
|
||||
knobLayer!.shadowOffset = CGSize(width:0.0, height:-6.5)
|
||||
knobLayer!.shadowRadius = 2.5
|
||||
knobLayer!.shadowOpacity = 0.15
|
||||
knobLayer?.masksToBounds = false
|
||||
rootLayer!.addSublayer(knobLayer!)
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
}
|
||||
|
||||
@IBAction func switchPress(_ sender: Any) {
|
||||
NSLog("Switch is now: \(switchButton.isOn)")
|
||||
NSLog("Switch is now: \((sender as! OGSwitch).isOn)")
|
||||
// perform(#selector(timer), with: nil, afterDelay: 3)
|
||||
}
|
||||
|
||||
|
||||
@@ -681,7 +681,7 @@
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
<window title="OGSwitch-DemoDemo" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="QvC-M9-y7g">
|
||||
<window title="OGSwitch-Demo" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="QvC-M9-y7g">
|
||||
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
|
||||
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
|
||||
<rect key="contentRect" x="335" y="390" width="480" height="360"/>
|
||||
@@ -696,7 +696,7 @@
|
||||
<userDefinedRuntimeAttributes>
|
||||
<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"/>
|
||||
<color key="value" name="systemGreenColor" catalog="System" colorSpace="catalog"/>
|
||||
</userDefinedRuntimeAttribute>
|
||||
</userDefinedRuntimeAttributes>
|
||||
<connections>
|
||||
@@ -704,26 +704,47 @@
|
||||
</connections>
|
||||
</customView>
|
||||
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Brb-kf-Oxi" customClass="OGSwitch" customModule="OGSwitch">
|
||||
<rect key="frame" x="159" y="63" width="163" height="96"/>
|
||||
<rect key="frame" x="140" y="60" width="46" height="28"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<userDefinedRuntimeAttributes>
|
||||
<userDefinedRuntimeAttribute type="image" keyPath="activeIcon" value="checkmark"/>
|
||||
<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>
|
||||
<userDefinedRuntimeAttribute type="image" keyPath="inactiveIcon" value="checkmark"/>
|
||||
</userDefinedRuntimeAttributes>
|
||||
<connections>
|
||||
<action selector="switchPress:" target="Voe-Tx-rLC" id="tTg-hX-q3I"/>
|
||||
</connections>
|
||||
</customView>
|
||||
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="dPq-0j-nKi" customClass="OGSwitch" customModule="OGSwitch">
|
||||
<rect key="frame" x="272" y="53" width="69" height="41"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<userDefinedRuntimeAttributes>
|
||||
<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="buu-wq-UpG"/>
|
||||
</connections>
|
||||
</customView>
|
||||
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="1VD-pu-2Ej" customClass="OGSwitch" customModule="OGSwitch">
|
||||
<rect key="frame" x="200" y="57" width="56" height="34"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<userDefinedRuntimeAttributes>
|
||||
<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="wRK-Gm-efR"/>
|
||||
</connections>
|
||||
</customView>
|
||||
</subviews>
|
||||
</view>
|
||||
<point key="canvasLocation" x="86" y="-105"/>
|
||||
<point key="canvasLocation" x="198" y="-127"/>
|
||||
</window>
|
||||
</objects>
|
||||
<resources>
|
||||
<image name="checkmark" width="35" height="34"/>
|
||||
</resources>
|
||||
</document>
|
||||
|
||||
@@ -7,19 +7,26 @@ Supports animation, custom aspect ratios, and knob images.
|
||||
|
||||
This is a `NSView` subclass that lets you create beautiful iOS-inspired switches easily.
|
||||
|
||||

|
||||

|
||||
|
||||
`OGSwitch` now also supports `IBDesignable` and renders directly in Interface Builder:
|
||||
|
||||

|
||||
|
||||
|
||||
## Installation (Carthage)
|
||||
Configure your Cartfile to use `OGSwitch`:
|
||||
|
||||
```github "OskarGroth/OGSwitch" ~> 2.0```
|
||||
|
||||
`OGSwitch` requires Swift 4.2.
|
||||
|
||||
## Usage
|
||||
|
||||
Create a custom `NSView` in Interface Builder and set it's class to `OGSwitch`.
|
||||
You can now style your switch from the inspector:
|
||||
|
||||

|
||||

|
||||
|
||||
The same values can be accessed from your code.
|
||||
|
||||
@@ -30,7 +37,7 @@ Inspired by ITSwitch by Ilija Tovilo.
|
||||
## License
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 Oskar Groth
|
||||
Copyright (c) 2018 Oskar Groth
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 62 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 288 KiB |
|
Before Width: | Height: | Size: 105 KiB After Width: | Height: | Size: 105 KiB |
Reference in New Issue
Block a user