├── Screenshot.png
├── KLSwitchDemo
├── en.lproj
│ ├── InfoPlist.strings
│ └── MainStoryboard.storyboard
├── Default.png
├── Default@2x.png
├── Default-568h@2x.png
├── KLAppDelegate.h
├── KLSwitchDemo-Prefix.pch
├── main.m
├── KLViewController.h
├── KLSwitchDemo-Info.plist
├── KLAppDelegate.m
└── KLViewController.m
├── .gitignore
├── KLSwitch
├── .DS_Store
├── KLSwitchTests
│ ├── en.lproj
│ │ └── InfoPlist.strings
│ ├── KLSwitchTests.h
│ ├── KLSwitchTests.m
│ └── KLSwitchTests-Info.plist
├── KLSwitch
│ ├── Resources
│ │ ├── lock-icon.png
│ │ └── lock-icon@2x.png
│ ├── KLSwitch-Prefix.pch
│ ├── KLSwitch.h
│ └── KLSwitch.m
└── KLSwitch.xcodeproj
│ ├── project.xcworkspace
│ └── contents.xcworkspacedata
│ ├── xcuserdata
│ ├── IBM.xcuserdatad
│ │ └── xcschemes
│ │ │ ├── xcschememanagement.plist
│ │ │ └── KLSwitch.xcscheme
│ └── kieranlafferty.xcuserdatad
│ │ └── xcschemes
│ │ ├── xcschememanagement.plist
│ │ └── KLSwitch.xcscheme
│ └── project.pbxproj
├── KLSwitchDemoTests
├── en.lproj
│ └── InfoPlist.strings
├── KLSwitchDemoTests.h
├── KLSwitchDemoTests.m
└── KLSwitchDemoTests-Info.plist
├── KLSwitchDemo.xcodeproj
├── xcuserdata
│ ├── IBM.xcuserdatad
│ │ ├── xcdebugger
│ │ │ └── Breakpoints.xcbkptlist
│ │ └── xcschemes
│ │ │ ├── xcschememanagement.plist
│ │ │ └── KLSwitchDemo.xcscheme
│ └── kieranlafferty.xcuserdatad
│ │ ├── xcdebugger
│ │ └── Breakpoints.xcbkptlist
│ │ └── xcschemes
│ │ ├── xcschememanagement.plist
│ │ └── KLSwitchDemo.xcscheme
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ ├── xcuserdata
│ │ ├── kieranlafferty.xcuserdatad
│ │ │ ├── UserInterfaceState.xcuserstate
│ │ │ └── WorkspaceSettings.xcsettings
│ │ └── IBM.xcuserdatad
│ │ │ └── WorkspaceSettings.xcsettings
│ └── xcshareddata
│ │ └── KLSwitchDemo.xccheckout
└── project.pbxproj
├── LICENSE
├── KLSwitch.podspec
└── README.md
/Screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KieranLafferty/KLSwitch/HEAD/Screenshot.png
--------------------------------------------------------------------------------
/KLSwitchDemo/en.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | *.xcuserstate
3 |
4 | *.xcuserstate
5 |
6 | .DS_Store
7 |
8 | .DS_Store
9 |
--------------------------------------------------------------------------------
/KLSwitch/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KieranLafferty/KLSwitch/HEAD/KLSwitch/.DS_Store
--------------------------------------------------------------------------------
/KLSwitchDemoTests/en.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------
/KLSwitch/KLSwitchTests/en.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------
/KLSwitchDemo/Default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KieranLafferty/KLSwitch/HEAD/KLSwitchDemo/Default.png
--------------------------------------------------------------------------------
/KLSwitchDemo/Default@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KieranLafferty/KLSwitch/HEAD/KLSwitchDemo/Default@2x.png
--------------------------------------------------------------------------------
/KLSwitchDemo/Default-568h@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KieranLafferty/KLSwitch/HEAD/KLSwitchDemo/Default-568h@2x.png
--------------------------------------------------------------------------------
/KLSwitch/KLSwitch/Resources/lock-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KieranLafferty/KLSwitch/HEAD/KLSwitch/KLSwitch/Resources/lock-icon.png
--------------------------------------------------------------------------------
/KLSwitch/KLSwitch/Resources/lock-icon@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KieranLafferty/KLSwitch/HEAD/KLSwitch/KLSwitch/Resources/lock-icon@2x.png
--------------------------------------------------------------------------------
/KLSwitchDemo.xcodeproj/xcuserdata/IBM.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/KLSwitchDemo.xcodeproj/xcuserdata/kieranlafferty.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/KLSwitch/KLSwitch/KLSwitch-Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header for all source files of the 'KLSwitch' target in the 'KLSwitch' project
3 | //
4 |
5 | #ifdef __OBJC__
6 | #import
7 | #endif
8 |
--------------------------------------------------------------------------------
/KLSwitch/KLSwitch.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/KLSwitchDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/KLSwitchDemo.xcodeproj/project.xcworkspace/xcuserdata/kieranlafferty.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KieranLafferty/KLSwitch/HEAD/KLSwitchDemo.xcodeproj/project.xcworkspace/xcuserdata/kieranlafferty.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/KLSwitch/KLSwitchTests/KLSwitchTests.h:
--------------------------------------------------------------------------------
1 | //
2 | // KLSwitchTests.h
3 | // KLSwitchTests
4 | //
5 | // Created by Kieran Lafferty on 2013-06-16.
6 | // Copyright (c) 2013 Kieran Lafferty. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface KLSwitchTests : SenTestCase
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/KLSwitchDemoTests/KLSwitchDemoTests.h:
--------------------------------------------------------------------------------
1 | //
2 | // KLSwitchDemoTests.h
3 | // KLSwitchDemoTests
4 | //
5 | // Created by Kieran Lafferty on 2013-06-16.
6 | // Copyright (c) 2013 Kieran Lafferty. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface KLSwitchDemoTests : SenTestCase
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/KLSwitchDemo/KLAppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // KLAppDelegate.h
3 | // KLSwitchDemo
4 | //
5 | // Created by Kieran Lafferty on 2013-06-16.
6 | // Copyright (c) 2013 Kieran Lafferty. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface KLAppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/KLSwitchDemo/KLSwitchDemo-Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header for all source files of the 'KLSwitchDemo' target in the 'KLSwitchDemo' project
3 | //
4 |
5 | #import
6 |
7 | #ifndef __IPHONE_5_0
8 | #warning "This project uses features only available in iOS SDK 5.0 and later."
9 | #endif
10 |
11 | #ifdef __OBJC__
12 | #import
13 | #import
14 | #endif
15 |
--------------------------------------------------------------------------------
/KLSwitchDemo/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // KLSwitchDemo
4 | //
5 | // Created by Kieran Lafferty on 2013-06-16.
6 | // Copyright (c) 2013 Kieran Lafferty. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #import "KLAppDelegate.h"
12 |
13 | int main(int argc, char *argv[])
14 | {
15 | @autoreleasepool {
16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([KLAppDelegate class]));
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/KLSwitchDemo.xcodeproj/project.xcworkspace/xcuserdata/IBM.xcuserdatad/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges
6 |
7 | SnapshotAutomaticallyBeforeSignificantChanges
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/KLSwitchDemo.xcodeproj/project.xcworkspace/xcuserdata/kieranlafferty.xcuserdatad/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges
6 |
7 | SnapshotAutomaticallyBeforeSignificantChanges
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/KLSwitch/KLSwitchTests/KLSwitchTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // KLSwitchTests.m
3 | // KLSwitchTests
4 | //
5 | // Created by Kieran Lafferty on 2013-06-16.
6 | // Copyright (c) 2013 Kieran Lafferty. All rights reserved.
7 | //
8 |
9 | #import "KLSwitchTests.h"
10 |
11 | @implementation KLSwitchTests
12 |
13 | - (void)setUp
14 | {
15 | [super setUp];
16 |
17 | // Set-up code here.
18 | }
19 |
20 | - (void)tearDown
21 | {
22 | // Tear-down code here.
23 |
24 | [super tearDown];
25 | }
26 |
27 | - (void)testExample
28 | {
29 | STFail(@"Unit tests are not implemented yet in KLSwitchTests");
30 | }
31 |
32 | @end
33 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright [yyyy] [name of copyright owner]
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
--------------------------------------------------------------------------------
/KLSwitchDemoTests/KLSwitchDemoTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // KLSwitchDemoTests.m
3 | // KLSwitchDemoTests
4 | //
5 | // Created by Kieran Lafferty on 2013-06-16.
6 | // Copyright (c) 2013 Kieran Lafferty. All rights reserved.
7 | //
8 |
9 | #import "KLSwitchDemoTests.h"
10 |
11 | @implementation KLSwitchDemoTests
12 |
13 | - (void)setUp
14 | {
15 | [super setUp];
16 |
17 | // Set-up code here.
18 | }
19 |
20 | - (void)tearDown
21 | {
22 | // Tear-down code here.
23 |
24 | [super tearDown];
25 | }
26 |
27 | - (void)testExample
28 | {
29 | STFail(@"Unit tests are not implemented yet in KLSwitchDemoTests");
30 | }
31 |
32 | @end
33 |
--------------------------------------------------------------------------------
/KLSwitch.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |s|
2 | s.name = "KLSwitch"
3 | s.ios.deployment_target = '5.0'
4 | s.version = "1.5"
5 | s.summary = "An iOS 7 UISwitch clone that works on iOS 5+."
6 | s.homepage = "http://www.cocoacontrols.com/platforms/ios/controls/klswitch"
7 | s.license = 'Apache 2.0'
8 | s.author = { "Kieran Lafferty" => "kieran.lafferty@gmail.com"}
9 | s.source = { :git => "https://github.com/KieranLafferty/KLSwitch.git", :tag => "1.5" }
10 | s.source_files = 'KLSwitch/KLSwitch/*.{h,m}'
11 | s.requires_arc = true
12 | s.frameworks = 'QuartzCore'
13 | s.frameworks = 'UIKit'
14 | end
--------------------------------------------------------------------------------
/KLSwitchDemo/KLViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // KLViewController.h
3 | // KLSwitchDemo
4 | //
5 | // Created by Kieran Lafferty on 2013-06-16.
6 | // Copyright (c) 2013 Kieran Lafferty. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 | @interface KLViewController : UIViewController
12 | @property (weak, nonatomic) IBOutlet KLSwitch *smallestSwitch;
13 | @property (weak, nonatomic) IBOutlet KLSwitch *smallSwitch;
14 | @property (weak, nonatomic) IBOutlet KLSwitch *mediumSwitch;
15 | @property (weak, nonatomic) IBOutlet KLSwitch *bigSwitch;
16 | @property (weak, nonatomic) IBOutlet KLSwitch *biggestSwitch;
17 | @end
18 |
--------------------------------------------------------------------------------
/KLSwitch/KLSwitch.xcodeproj/xcuserdata/IBM.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | KLSwitch.xcscheme
8 |
9 | orderHint
10 | 1
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 7710F4F0176DE33900771BA7
16 |
17 | primary
18 |
19 |
20 | 7710F501176DE33900771BA7
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/KLSwitchDemo.xcodeproj/xcuserdata/IBM.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | KLSwitchDemo.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 7710F52D176DEAF200771BA7
16 |
17 | primary
18 |
19 |
20 | 7710F553176DEAF200771BA7
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/KLSwitch/KLSwitch.xcodeproj/xcuserdata/kieranlafferty.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | KLSwitch.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 7710F4F0176DE33900771BA7
16 |
17 | primary
18 |
19 |
20 | 7710F501176DE33900771BA7
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/KLSwitchDemo.xcodeproj/xcuserdata/kieranlafferty.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | KLSwitchDemo.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 7710F52D176DEAF200771BA7
16 |
17 | primary
18 |
19 |
20 | 7710F553176DEAF200771BA7
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/KLSwitch/KLSwitchTests/KLSwitchTests-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | KL.${PRODUCT_NAME:rfc1034identifier}
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | BNDL
15 | CFBundleShortVersionString
16 | 1.0
17 | CFBundleSignature
18 | ????
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/KLSwitchDemoTests/KLSwitchDemoTests-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | KL.${PRODUCT_NAME:rfc1034identifier}
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | BNDL
15 | CFBundleShortVersionString
16 | 1.0
17 | CFBundleSignature
18 | ????
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/KLSwitchDemo/KLSwitchDemo-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleDisplayName
8 | ${PRODUCT_NAME}
9 | CFBundleExecutable
10 | ${EXECUTABLE_NAME}
11 | CFBundleIdentifier
12 | KL.${PRODUCT_NAME:rfc1034identifier}
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | ${PRODUCT_NAME}
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | 1.0
25 | LSRequiresIPhoneOS
26 |
27 | UIMainStoryboardFile
28 | MainStoryboard
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/KLSwitchDemo.xcodeproj/project.xcworkspace/xcshareddata/KLSwitchDemo.xccheckout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDESourceControlProjectIdentifier
6 | 49542714-FB02-4C54-9DE4-C42D132D8CE0
7 | IDESourceControlProjectName
8 | KLSwitchDemo
9 | IDESourceControlProjectOriginsDictionary
10 |
11 | 2AB8DE3D-7D3B-4F84-A62F-9089C0BB748D
12 | https://github.com/KieranLafferty/KLSwitch.git
13 |
14 | IDESourceControlProjectPath
15 | KLSwitchDemo.xcodeproj/project.xcworkspace
16 | IDESourceControlProjectRelativeInstallPathDictionary
17 |
18 | 2AB8DE3D-7D3B-4F84-A62F-9089C0BB748D
19 | ../..
20 |
21 | IDESourceControlProjectURL
22 | https://github.com/KieranLafferty/KLSwitch.git
23 | IDESourceControlProjectVersion
24 | 110
25 | IDESourceControlProjectWCCIdentifier
26 | 2AB8DE3D-7D3B-4F84-A62F-9089C0BB748D
27 | IDESourceControlProjectWCConfigurations
28 |
29 |
30 | IDESourceControlRepositoryExtensionIdentifierKey
31 | public.vcs.git
32 | IDESourceControlWCCIdentifierKey
33 | 2AB8DE3D-7D3B-4F84-A62F-9089C0BB748D
34 | IDESourceControlWCCName
35 | KLSwitchDemo
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/KLSwitch/KLSwitch/KLSwitch.h:
--------------------------------------------------------------------------------
1 | //
2 | // KLSwitch.h
3 | // KLSwitch
4 | //
5 | // Created by Kieran Lafferty on 2013-06-15.
6 | // Copyright (c) 2013 Kieran Lafferty. All rights reserved.
7 | //
8 | // https://github.com/KieranLafferty/KLSwitch
9 |
10 | #import
11 | #import
12 |
13 | #define LOCK_IMAGE_SUBVIEW 100
14 |
15 | typedef void(^changeHandler)(BOOL isOn);
16 |
17 | @interface KLSwitch : UIControl
18 | //UISwitch interface
19 | @property(nonatomic, strong) UIImage *onImage NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; //Currently this does nothing
20 | @property(nonatomic, strong) UIImage *offImage NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; //Currently this does nothing
21 |
22 | @property(nonatomic, strong) UIColor *onTintColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
23 | @property(nonatomic, strong) UIColor *tintColor NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
24 | @property(nonatomic, strong) UIColor *thumbTintColor NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
25 |
26 |
27 | ///Additional color options provided by KLSwitch only
28 | @property(nonatomic, strong) UIColor *contrastColor;
29 | @property(nonatomic, strong) UIColor *thumbBorderColor;
30 |
31 |
32 | @property(nonatomic, getter=isOn) BOOL on;
33 | @property(nonatomic, getter=isLocked) BOOL locked;
34 |
35 | //Custom completion block initiated by value change (on/off)
36 | @property(nonatomic, copy) changeHandler didChangeHandler;
37 |
38 | //Percent (0.0 - 1.0) of the control to travel while panning before a switch toggle is activated
39 | @property(nonatomic, assign) CGFloat panActivationThreshold;
40 |
41 | //Set to true if you want to maintain 51x31 proportions, false if you want to set the frame to anything
42 | @property(nonatomic, assign) BOOL shouldConstrainFrame;
43 |
44 | //Initializers
45 | - (id)initWithFrame:(CGRect)frame;
46 | - (id)initWithFrame:(CGRect)frame
47 | didChangeHandler:(changeHandler) didChangeHandler;
48 |
49 | //Events
50 | - (void)setOn:(BOOL)on animated:(BOOL)animated;
51 | - (void)setLocked:(BOOL)locked;
52 |
53 | @end
54 |
55 |
--------------------------------------------------------------------------------
/KLSwitchDemo/KLAppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // KLAppDelegate.m
3 | // KLSwitchDemo
4 | //
5 | // Created by Kieran Lafferty on 2013-06-16.
6 | // Copyright (c) 2013 Kieran Lafferty. All rights reserved.
7 | //
8 |
9 | #import "KLAppDelegate.h"
10 |
11 | @implementation KLAppDelegate
12 |
13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
14 | {
15 | // Override point for customization after application launch.
16 | return YES;
17 | }
18 |
19 | - (void)applicationWillResignActive:(UIApplication *)application
20 | {
21 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
22 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
23 | }
24 |
25 | - (void)applicationDidEnterBackground:(UIApplication *)application
26 | {
27 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
28 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
29 | }
30 |
31 | - (void)applicationWillEnterForeground:(UIApplication *)application
32 | {
33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
34 | }
35 |
36 | - (void)applicationDidBecomeActive:(UIApplication *)application
37 | {
38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
39 | }
40 |
41 | - (void)applicationWillTerminate:(UIApplication *)application
42 | {
43 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
44 | }
45 |
46 | @end
47 |
--------------------------------------------------------------------------------
/KLSwitchDemo/KLViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // KLViewController.m
3 | // KLSwitchDemo
4 | //
5 | // Created by Kieran Lafferty on 2013-06-16.
6 | // Copyright (c) 2013 Kieran Lafferty. All rights reserved.
7 | //
8 |
9 | #import "KLViewController.h"
10 | #define kGreenColor [UIColor colorWithRed:144/255.0 green: 202/255.0 blue: 119/255.0 alpha: 1.0]
11 | #define kBlueColor [UIColor colorWithRed:129/255.0 green: 198/255.0 blue: 221/255.0 alpha: 1.0]
12 | #define kYellowColor [UIColor colorWithRed:233/255.0 green: 182/255.0 blue: 77/255.0 alpha: 1.0]
13 | #define kOrangeColor [UIColor colorWithRed:288/255.0 green: 135/255.0 blue: 67/255.0 alpha: 1.0]
14 | #define kRedColor [UIColor colorWithRed:158/255.0 green: 59/255.0 blue: 51/255.0 alpha: 1.0]
15 | @interface KLViewController ()
16 |
17 | @end
18 |
19 | @implementation KLViewController
20 |
21 | - (void)viewDidLoad
22 | {
23 | [super viewDidLoad];
24 | [KLSwitch class]; //Required for the class to be linked properly when only linked through IB
25 |
26 | [self.smallestSwitch setOnTintColor: kGreenColor];
27 | [self.smallSwitch setOnTintColor: kBlueColor];
28 | [self.mediumSwitch setOnTintColor: kYellowColor];
29 | [self.bigSwitch setOnTintColor: kOrangeColor];
30 | [self.biggestSwitch setOnTintColor: kRedColor];
31 |
32 | [self.smallestSwitch setOn: YES
33 | animated: YES];
34 | [self.smallestSwitch setDidChangeHandler:^(BOOL isOn) {
35 | NSLog(@"Smallest switch changed to %d", isOn);
36 | }];
37 |
38 | [self.smallSwitch setOn: YES
39 | animated: YES];
40 | [self.smallSwitch setDidChangeHandler:^(BOOL isOn) {
41 | NSLog(@"Small switch changed to %d", isOn);
42 | }];
43 |
44 | [self.mediumSwitch setOn: YES
45 | animated: YES];
46 | [self.mediumSwitch setDidChangeHandler:^(BOOL isOn) {
47 | NSLog(@"Medium switch changed to %d", isOn);
48 | }];
49 |
50 | [self.bigSwitch setOn: YES
51 | animated: YES];
52 | [self.bigSwitch setDidChangeHandler:^(BOOL isOn) {
53 | NSLog(@"Big switch changed to %d", isOn);
54 | }];
55 |
56 | [self.biggestSwitch setOn: YES
57 | animated: YES];
58 | [self.biggestSwitch setDidChangeHandler:^(BOOL isOn) {
59 | NSLog(@"Biggest switch changed to %d", isOn);
60 | }];
61 | }
62 |
63 | @end
64 |
--------------------------------------------------------------------------------
/KLSwitch/KLSwitch.xcodeproj/xcuserdata/IBM.xcuserdatad/xcschemes/KLSwitch.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
52 |
53 |
54 |
55 |
61 |
62 |
64 |
65 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/KLSwitch/KLSwitch.xcodeproj/xcuserdata/kieranlafferty.xcuserdatad/xcschemes/KLSwitch.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
52 |
53 |
54 |
55 |
61 |
62 |
64 |
65 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/KLSwitchDemo.xcodeproj/xcuserdata/IBM.xcuserdatad/xcschemes/KLSwitchDemo.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
49 |
50 |
51 |
52 |
61 |
62 |
68 |
69 |
70 |
71 |
72 |
73 |
79 |
80 |
86 |
87 |
88 |
89 |
91 |
92 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/KLSwitchDemo.xcodeproj/xcuserdata/kieranlafferty.xcuserdatad/xcschemes/KLSwitchDemo.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
49 |
50 |
51 |
52 |
61 |
62 |
68 |
69 |
70 |
71 |
72 |
73 |
79 |
80 |
86 |
87 |
88 |
89 |
91 |
92 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | KLSwitch
2 | =======
3 | An iOS 7 UISwitch clone that works on iOS 5+
4 |
5 | https://www.cocoacontrols.com/controls/klswitch
6 |
7 |
8 |
9 | Requires ARC
10 |
11 |
12 |
13 |
16 |
17 | ## Goal ##
18 | 1. Create the iOS 7 UISwitch to be compatible with iOS 5+
19 | 2. Create a drop in replacement for UISwitch
20 |
21 |
22 | ## Installation ##
23 |
24 |
25 | 1. Drag the KLSwitch.xcodeproj to your existing project
26 | 2. Under Build Phases on your project's Xcode Project file add 'KLSwitch(KLSwitch)' to your Target Dependancies
27 | 3. Under Build on your Xcode Project file add 'libKLSwitch' & QuartzCore.framework under Link Binary With Libraries
28 | 4. Include #import in any file you wish to use
29 |
30 |
31 | Via CocoaPods
32 | Add the following line to your podfile
33 |
34 | pod 'KLSwitch'
35 |
36 | ## Usage ##
37 | Interface is exactly the same as for the regular UISwitch you know and love (http://developer.apple.com/library/ios/#documentation/uikit/reference/UISwitch_Class/Reference/Reference.html)
38 |
39 | Added an event handler block to recieve state changes when the switch is toggled on/off which can be set as follows:
40 |
41 | mySwitch.didChangeHandler = ^(BOOL isOn) {
42 | //Do something useful with it here
43 | }
44 |
45 | Or it can be set using the custom initializer
46 |
47 | - (id)initWithFrame:(CGRect)frame
48 | didChangeHandler:(changeHandler) didChangeHandler;
49 |
50 |
51 | See Demo project for sample usage using Interface Builder
52 |
53 |
54 | ## Config ##
55 | The visual appearance can be tweaked by changing the constants in KLNoteViewController.m:
56 |
57 | //Appearance Defaults - Colors
58 | //Track Colors
59 | #define kDefaultTrackOnColor [UIColor colorWithRed:83/255.0 green: 214/255.0 blue: 105/255.0 alpha: 1]
60 | #define kDefaultTrackOffColor [UIColor colorWithWhite: 0.9 alpha:1.0]
61 | #define kDefaultTrackContrastColor [UIColor whiteColor]
62 |
63 | //Thumb Colors
64 | #define kDefaultThumbTintColor [UIColor whiteColor]
65 | #define kDefaultThumbBorderColor [UIColor colorWithWhite: 0.9 alpha:1.0]
66 |
67 | //Appearance - Layout
68 |
69 | //Size of knob with respect to the control - Must be a multiple of 2
70 | #define kKnobOffset 2.0
71 | #define kKnobTrackingGrowthRatio 1.2 //Amount to grow the thumb on press down
72 |
73 | #define kDefaultPanActivationThreshold 0.7 //Number between 0.0 - 1.0 describing how far user must drag before initiating the switch
74 |
75 | //Appearance - Animations
76 | #define kDefaultAnimationScaleLength 0.10 //Length of time for the thumb to grow on press down
77 | #define kDefaultAnimationSlideLength 0.25 //Length of time to slide the thumb from left/right to right/left
78 |
79 | #define kSwitchTrackContrastViewShrinkFactor 0.00
80 |
81 |
82 |
83 | ## Contact ##
84 |
85 | * [@kieran_lafferty](https://twitter.com/kieran_lafferty) on Twitter
86 | * [@kieranlafferty](https://github.com/kieranlafferty) on Github
87 | * kieran.lafferty [at] gmail [dot] com
88 |
89 | ## License ##
90 |
91 | Copyrigh 2013 Kieran Lafferty
92 |
93 | Licensed under the Apache License, Version 2.0 (the "License");
94 | you may not use this file except in compliance with the License.
95 | You may obtain a copy of the License at
96 |
97 | http://www.apache.org/licenses/LICENSE-2.0
98 |
99 | Unless required by applicable law or agreed to in writing, software
100 | distributed under the License is distributed on an "AS IS" BASIS,
101 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
102 | See the License for the specific language governing permissions and
103 | limitations under the License.
104 |
--------------------------------------------------------------------------------
/KLSwitchDemo/en.lproj/MainStoryboard.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/KLSwitch/KLSwitch.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 7710F4F5176DE33900771BA7 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7710F4F4176DE33900771BA7 /* Foundation.framework */; };
11 | 7710F504176DE33900771BA7 /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7710F503176DE33900771BA7 /* SenTestingKit.framework */; };
12 | 7710F506176DE33900771BA7 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7710F505176DE33900771BA7 /* UIKit.framework */; };
13 | 7710F507176DE33900771BA7 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7710F4F4176DE33900771BA7 /* Foundation.framework */; };
14 | 7710F50A176DE33900771BA7 /* libKLSwitch.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7710F4F1176DE33900771BA7 /* libKLSwitch.a */; };
15 | 7710F510176DE33900771BA7 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 7710F50E176DE33900771BA7 /* InfoPlist.strings */; };
16 | 7710F513176DE33900771BA7 /* KLSwitchTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7710F512176DE33900771BA7 /* KLSwitchTests.m */; };
17 | 7710F51E176DE41700771BA7 /* KLSwitch.m in Sources */ = {isa = PBXBuildFile; fileRef = 7710F51D176DE41700771BA7 /* KLSwitch.m */; };
18 | 7710F520176DE42300771BA7 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7710F51F176DE42300771BA7 /* QuartzCore.framework */; };
19 | 7710F522176DE42800771BA7 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7710F521176DE42800771BA7 /* UIKit.framework */; };
20 | 7710F523176DE42C00771BA7 /* KLSwitch.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7710F51C176DE41700771BA7 /* KLSwitch.h */; };
21 | 7710F524176DE43200771BA7 /* KLSwitch.m in Sources */ = {isa = PBXBuildFile; fileRef = 7710F51D176DE41700771BA7 /* KLSwitch.m */; };
22 | /* End PBXBuildFile section */
23 |
24 | /* Begin PBXContainerItemProxy section */
25 | 7710F508176DE33900771BA7 /* PBXContainerItemProxy */ = {
26 | isa = PBXContainerItemProxy;
27 | containerPortal = 7710F4E9176DE33900771BA7 /* Project object */;
28 | proxyType = 1;
29 | remoteGlobalIDString = 7710F4F0176DE33900771BA7;
30 | remoteInfo = KLSwitch;
31 | };
32 | /* End PBXContainerItemProxy section */
33 |
34 | /* Begin PBXCopyFilesBuildPhase section */
35 | 7710F4EF176DE33900771BA7 /* CopyFiles */ = {
36 | isa = PBXCopyFilesBuildPhase;
37 | buildActionMask = 2147483647;
38 | dstPath = "include/${PRODUCT_NAME}";
39 | dstSubfolderSpec = 16;
40 | files = (
41 | 7710F523176DE42C00771BA7 /* KLSwitch.h in CopyFiles */,
42 | );
43 | runOnlyForDeploymentPostprocessing = 0;
44 | };
45 | /* End PBXCopyFilesBuildPhase section */
46 |
47 | /* Begin PBXFileReference section */
48 | 7710F4F1176DE33900771BA7 /* libKLSwitch.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libKLSwitch.a; sourceTree = BUILT_PRODUCTS_DIR; };
49 | 7710F4F4176DE33900771BA7 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
50 | 7710F4F8176DE33900771BA7 /* KLSwitch-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "KLSwitch-Prefix.pch"; sourceTree = ""; };
51 | 7710F502176DE33900771BA7 /* KLSwitchTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = KLSwitchTests.octest; sourceTree = BUILT_PRODUCTS_DIR; };
52 | 7710F503176DE33900771BA7 /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; };
53 | 7710F505176DE33900771BA7 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; };
54 | 7710F50D176DE33900771BA7 /* KLSwitchTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "KLSwitchTests-Info.plist"; sourceTree = ""; };
55 | 7710F50F176DE33900771BA7 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; };
56 | 7710F511176DE33900771BA7 /* KLSwitchTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KLSwitchTests.h; sourceTree = ""; };
57 | 7710F512176DE33900771BA7 /* KLSwitchTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KLSwitchTests.m; sourceTree = ""; };
58 | 7710F51C176DE41700771BA7 /* KLSwitch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KLSwitch.h; sourceTree = ""; };
59 | 7710F51D176DE41700771BA7 /* KLSwitch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KLSwitch.m; sourceTree = ""; };
60 | 7710F51F176DE42300771BA7 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
61 | 7710F521176DE42800771BA7 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
62 | /* End PBXFileReference section */
63 |
64 | /* Begin PBXFrameworksBuildPhase section */
65 | 7710F4EE176DE33900771BA7 /* Frameworks */ = {
66 | isa = PBXFrameworksBuildPhase;
67 | buildActionMask = 2147483647;
68 | files = (
69 | 7710F522176DE42800771BA7 /* UIKit.framework in Frameworks */,
70 | 7710F520176DE42300771BA7 /* QuartzCore.framework in Frameworks */,
71 | 7710F4F5176DE33900771BA7 /* Foundation.framework in Frameworks */,
72 | );
73 | runOnlyForDeploymentPostprocessing = 0;
74 | };
75 | 7710F4FE176DE33900771BA7 /* Frameworks */ = {
76 | isa = PBXFrameworksBuildPhase;
77 | buildActionMask = 2147483647;
78 | files = (
79 | 7710F504176DE33900771BA7 /* SenTestingKit.framework in Frameworks */,
80 | 7710F506176DE33900771BA7 /* UIKit.framework in Frameworks */,
81 | 7710F507176DE33900771BA7 /* Foundation.framework in Frameworks */,
82 | 7710F50A176DE33900771BA7 /* libKLSwitch.a in Frameworks */,
83 | );
84 | runOnlyForDeploymentPostprocessing = 0;
85 | };
86 | /* End PBXFrameworksBuildPhase section */
87 |
88 | /* Begin PBXGroup section */
89 | 7710F4E8176DE33900771BA7 = {
90 | isa = PBXGroup;
91 | children = (
92 | 7710F4F6176DE33900771BA7 /* KLSwitch */,
93 | 7710F50B176DE33900771BA7 /* KLSwitchTests */,
94 | 7710F4F3176DE33900771BA7 /* Frameworks */,
95 | 7710F4F2176DE33900771BA7 /* Products */,
96 | );
97 | sourceTree = "";
98 | };
99 | 7710F4F2176DE33900771BA7 /* Products */ = {
100 | isa = PBXGroup;
101 | children = (
102 | 7710F4F1176DE33900771BA7 /* libKLSwitch.a */,
103 | 7710F502176DE33900771BA7 /* KLSwitchTests.octest */,
104 | );
105 | name = Products;
106 | sourceTree = "";
107 | };
108 | 7710F4F3176DE33900771BA7 /* Frameworks */ = {
109 | isa = PBXGroup;
110 | children = (
111 | 7710F521176DE42800771BA7 /* UIKit.framework */,
112 | 7710F51F176DE42300771BA7 /* QuartzCore.framework */,
113 | 7710F4F4176DE33900771BA7 /* Foundation.framework */,
114 | 7710F503176DE33900771BA7 /* SenTestingKit.framework */,
115 | 7710F505176DE33900771BA7 /* UIKit.framework */,
116 | );
117 | name = Frameworks;
118 | sourceTree = "";
119 | };
120 | 7710F4F6176DE33900771BA7 /* KLSwitch */ = {
121 | isa = PBXGroup;
122 | children = (
123 | 7710F51C176DE41700771BA7 /* KLSwitch.h */,
124 | 7710F51D176DE41700771BA7 /* KLSwitch.m */,
125 | 7710F4F7176DE33900771BA7 /* Supporting Files */,
126 | );
127 | path = KLSwitch;
128 | sourceTree = "";
129 | };
130 | 7710F4F7176DE33900771BA7 /* Supporting Files */ = {
131 | isa = PBXGroup;
132 | children = (
133 | 7710F4F8176DE33900771BA7 /* KLSwitch-Prefix.pch */,
134 | );
135 | name = "Supporting Files";
136 | sourceTree = "";
137 | };
138 | 7710F50B176DE33900771BA7 /* KLSwitchTests */ = {
139 | isa = PBXGroup;
140 | children = (
141 | 7710F511176DE33900771BA7 /* KLSwitchTests.h */,
142 | 7710F512176DE33900771BA7 /* KLSwitchTests.m */,
143 | 7710F50C176DE33900771BA7 /* Supporting Files */,
144 | );
145 | path = KLSwitchTests;
146 | sourceTree = "";
147 | };
148 | 7710F50C176DE33900771BA7 /* Supporting Files */ = {
149 | isa = PBXGroup;
150 | children = (
151 | 7710F50D176DE33900771BA7 /* KLSwitchTests-Info.plist */,
152 | 7710F50E176DE33900771BA7 /* InfoPlist.strings */,
153 | );
154 | name = "Supporting Files";
155 | sourceTree = "";
156 | };
157 | /* End PBXGroup section */
158 |
159 | /* Begin PBXNativeTarget section */
160 | 7710F4F0176DE33900771BA7 /* KLSwitch */ = {
161 | isa = PBXNativeTarget;
162 | buildConfigurationList = 7710F516176DE33900771BA7 /* Build configuration list for PBXNativeTarget "KLSwitch" */;
163 | buildPhases = (
164 | 7710F4ED176DE33900771BA7 /* Sources */,
165 | 7710F4EE176DE33900771BA7 /* Frameworks */,
166 | 7710F4EF176DE33900771BA7 /* CopyFiles */,
167 | );
168 | buildRules = (
169 | );
170 | dependencies = (
171 | );
172 | name = KLSwitch;
173 | productName = KLSwitch;
174 | productReference = 7710F4F1176DE33900771BA7 /* libKLSwitch.a */;
175 | productType = "com.apple.product-type.library.static";
176 | };
177 | 7710F501176DE33900771BA7 /* KLSwitchTests */ = {
178 | isa = PBXNativeTarget;
179 | buildConfigurationList = 7710F519176DE33900771BA7 /* Build configuration list for PBXNativeTarget "KLSwitchTests" */;
180 | buildPhases = (
181 | 7710F4FD176DE33900771BA7 /* Sources */,
182 | 7710F4FE176DE33900771BA7 /* Frameworks */,
183 | 7710F4FF176DE33900771BA7 /* Resources */,
184 | 7710F500176DE33900771BA7 /* ShellScript */,
185 | );
186 | buildRules = (
187 | );
188 | dependencies = (
189 | 7710F509176DE33900771BA7 /* PBXTargetDependency */,
190 | );
191 | name = KLSwitchTests;
192 | productName = KLSwitchTests;
193 | productReference = 7710F502176DE33900771BA7 /* KLSwitchTests.octest */;
194 | productType = "com.apple.product-type.bundle";
195 | };
196 | /* End PBXNativeTarget section */
197 |
198 | /* Begin PBXProject section */
199 | 7710F4E9176DE33900771BA7 /* Project object */ = {
200 | isa = PBXProject;
201 | attributes = {
202 | LastUpgradeCheck = 0460;
203 | ORGANIZATIONNAME = "Kieran Lafferty";
204 | };
205 | buildConfigurationList = 7710F4EC176DE33900771BA7 /* Build configuration list for PBXProject "KLSwitch" */;
206 | compatibilityVersion = "Xcode 3.2";
207 | developmentRegion = English;
208 | hasScannedForEncodings = 0;
209 | knownRegions = (
210 | en,
211 | );
212 | mainGroup = 7710F4E8176DE33900771BA7;
213 | productRefGroup = 7710F4F2176DE33900771BA7 /* Products */;
214 | projectDirPath = "";
215 | projectRoot = "";
216 | targets = (
217 | 7710F4F0176DE33900771BA7 /* KLSwitch */,
218 | 7710F501176DE33900771BA7 /* KLSwitchTests */,
219 | );
220 | };
221 | /* End PBXProject section */
222 |
223 | /* Begin PBXResourcesBuildPhase section */
224 | 7710F4FF176DE33900771BA7 /* Resources */ = {
225 | isa = PBXResourcesBuildPhase;
226 | buildActionMask = 2147483647;
227 | files = (
228 | 7710F510176DE33900771BA7 /* InfoPlist.strings in Resources */,
229 | );
230 | runOnlyForDeploymentPostprocessing = 0;
231 | };
232 | /* End PBXResourcesBuildPhase section */
233 |
234 | /* Begin PBXShellScriptBuildPhase section */
235 | 7710F500176DE33900771BA7 /* ShellScript */ = {
236 | isa = PBXShellScriptBuildPhase;
237 | buildActionMask = 2147483647;
238 | files = (
239 | );
240 | inputPaths = (
241 | );
242 | outputPaths = (
243 | );
244 | runOnlyForDeploymentPostprocessing = 0;
245 | shellPath = /bin/sh;
246 | shellScript = "# Run the unit tests in this test bundle.\n\"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests\"\n";
247 | };
248 | /* End PBXShellScriptBuildPhase section */
249 |
250 | /* Begin PBXSourcesBuildPhase section */
251 | 7710F4ED176DE33900771BA7 /* Sources */ = {
252 | isa = PBXSourcesBuildPhase;
253 | buildActionMask = 2147483647;
254 | files = (
255 | 7710F524176DE43200771BA7 /* KLSwitch.m in Sources */,
256 | );
257 | runOnlyForDeploymentPostprocessing = 0;
258 | };
259 | 7710F4FD176DE33900771BA7 /* Sources */ = {
260 | isa = PBXSourcesBuildPhase;
261 | buildActionMask = 2147483647;
262 | files = (
263 | 7710F513176DE33900771BA7 /* KLSwitchTests.m in Sources */,
264 | 7710F51E176DE41700771BA7 /* KLSwitch.m in Sources */,
265 | );
266 | runOnlyForDeploymentPostprocessing = 0;
267 | };
268 | /* End PBXSourcesBuildPhase section */
269 |
270 | /* Begin PBXTargetDependency section */
271 | 7710F509176DE33900771BA7 /* PBXTargetDependency */ = {
272 | isa = PBXTargetDependency;
273 | target = 7710F4F0176DE33900771BA7 /* KLSwitch */;
274 | targetProxy = 7710F508176DE33900771BA7 /* PBXContainerItemProxy */;
275 | };
276 | /* End PBXTargetDependency section */
277 |
278 | /* Begin PBXVariantGroup section */
279 | 7710F50E176DE33900771BA7 /* InfoPlist.strings */ = {
280 | isa = PBXVariantGroup;
281 | children = (
282 | 7710F50F176DE33900771BA7 /* en */,
283 | );
284 | name = InfoPlist.strings;
285 | sourceTree = "";
286 | };
287 | /* End PBXVariantGroup section */
288 |
289 | /* Begin XCBuildConfiguration section */
290 | 7710F514176DE33900771BA7 /* Debug */ = {
291 | isa = XCBuildConfiguration;
292 | buildSettings = {
293 | ALWAYS_SEARCH_USER_PATHS = NO;
294 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
295 | CLANG_CXX_LIBRARY = "libc++";
296 | CLANG_ENABLE_OBJC_ARC = YES;
297 | CLANG_WARN_CONSTANT_CONVERSION = YES;
298 | CLANG_WARN_EMPTY_BODY = YES;
299 | CLANG_WARN_ENUM_CONVERSION = YES;
300 | CLANG_WARN_INT_CONVERSION = YES;
301 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
302 | COPY_PHASE_STRIP = NO;
303 | GCC_C_LANGUAGE_STANDARD = gnu99;
304 | GCC_DYNAMIC_NO_PIC = NO;
305 | GCC_OPTIMIZATION_LEVEL = 0;
306 | GCC_PREPROCESSOR_DEFINITIONS = (
307 | "DEBUG=1",
308 | "$(inherited)",
309 | );
310 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
311 | GCC_WARN_ABOUT_RETURN_TYPE = YES;
312 | GCC_WARN_UNINITIALIZED_AUTOS = YES;
313 | GCC_WARN_UNUSED_VARIABLE = YES;
314 | IPHONEOS_DEPLOYMENT_TARGET = 5.0;
315 | ONLY_ACTIVE_ARCH = YES;
316 | SDKROOT = iphoneos;
317 | };
318 | name = Debug;
319 | };
320 | 7710F515176DE33900771BA7 /* Release */ = {
321 | isa = XCBuildConfiguration;
322 | buildSettings = {
323 | ALWAYS_SEARCH_USER_PATHS = NO;
324 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
325 | CLANG_CXX_LIBRARY = "libc++";
326 | CLANG_ENABLE_OBJC_ARC = YES;
327 | CLANG_WARN_CONSTANT_CONVERSION = YES;
328 | CLANG_WARN_EMPTY_BODY = YES;
329 | CLANG_WARN_ENUM_CONVERSION = YES;
330 | CLANG_WARN_INT_CONVERSION = YES;
331 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
332 | COPY_PHASE_STRIP = YES;
333 | GCC_C_LANGUAGE_STANDARD = gnu99;
334 | GCC_WARN_ABOUT_RETURN_TYPE = YES;
335 | GCC_WARN_UNINITIALIZED_AUTOS = YES;
336 | GCC_WARN_UNUSED_VARIABLE = YES;
337 | IPHONEOS_DEPLOYMENT_TARGET = 5.0;
338 | SDKROOT = iphoneos;
339 | VALIDATE_PRODUCT = YES;
340 | };
341 | name = Release;
342 | };
343 | 7710F517176DE33900771BA7 /* Debug */ = {
344 | isa = XCBuildConfiguration;
345 | buildSettings = {
346 | DSTROOT = /tmp/KLSwitch.dst;
347 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
348 | GCC_PREFIX_HEADER = "KLSwitch/KLSwitch-Prefix.pch";
349 | OTHER_LDFLAGS = "-ObjC";
350 | PRODUCT_NAME = "$(TARGET_NAME)";
351 | SKIP_INSTALL = YES;
352 | };
353 | name = Debug;
354 | };
355 | 7710F518176DE33900771BA7 /* Release */ = {
356 | isa = XCBuildConfiguration;
357 | buildSettings = {
358 | DSTROOT = /tmp/KLSwitch.dst;
359 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
360 | GCC_PREFIX_HEADER = "KLSwitch/KLSwitch-Prefix.pch";
361 | OTHER_LDFLAGS = "-ObjC";
362 | PRODUCT_NAME = "$(TARGET_NAME)";
363 | SKIP_INSTALL = YES;
364 | };
365 | name = Release;
366 | };
367 | 7710F51A176DE33900771BA7 /* Debug */ = {
368 | isa = XCBuildConfiguration;
369 | buildSettings = {
370 | FRAMEWORK_SEARCH_PATHS = (
371 | "\"$(SDKROOT)/Developer/Library/Frameworks\"",
372 | "\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"",
373 | );
374 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
375 | GCC_PREFIX_HEADER = "KLSwitch/KLSwitch-Prefix.pch";
376 | INFOPLIST_FILE = "KLSwitchTests/KLSwitchTests-Info.plist";
377 | PRODUCT_NAME = "$(TARGET_NAME)";
378 | WRAPPER_EXTENSION = octest;
379 | };
380 | name = Debug;
381 | };
382 | 7710F51B176DE33900771BA7 /* Release */ = {
383 | isa = XCBuildConfiguration;
384 | buildSettings = {
385 | FRAMEWORK_SEARCH_PATHS = (
386 | "\"$(SDKROOT)/Developer/Library/Frameworks\"",
387 | "\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"",
388 | );
389 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
390 | GCC_PREFIX_HEADER = "KLSwitch/KLSwitch-Prefix.pch";
391 | INFOPLIST_FILE = "KLSwitchTests/KLSwitchTests-Info.plist";
392 | PRODUCT_NAME = "$(TARGET_NAME)";
393 | WRAPPER_EXTENSION = octest;
394 | };
395 | name = Release;
396 | };
397 | /* End XCBuildConfiguration section */
398 |
399 | /* Begin XCConfigurationList section */
400 | 7710F4EC176DE33900771BA7 /* Build configuration list for PBXProject "KLSwitch" */ = {
401 | isa = XCConfigurationList;
402 | buildConfigurations = (
403 | 7710F514176DE33900771BA7 /* Debug */,
404 | 7710F515176DE33900771BA7 /* Release */,
405 | );
406 | defaultConfigurationIsVisible = 0;
407 | defaultConfigurationName = Release;
408 | };
409 | 7710F516176DE33900771BA7 /* Build configuration list for PBXNativeTarget "KLSwitch" */ = {
410 | isa = XCConfigurationList;
411 | buildConfigurations = (
412 | 7710F517176DE33900771BA7 /* Debug */,
413 | 7710F518176DE33900771BA7 /* Release */,
414 | );
415 | defaultConfigurationIsVisible = 0;
416 | defaultConfigurationName = Release;
417 | };
418 | 7710F519176DE33900771BA7 /* Build configuration list for PBXNativeTarget "KLSwitchTests" */ = {
419 | isa = XCConfigurationList;
420 | buildConfigurations = (
421 | 7710F51A176DE33900771BA7 /* Debug */,
422 | 7710F51B176DE33900771BA7 /* Release */,
423 | );
424 | defaultConfigurationIsVisible = 0;
425 | defaultConfigurationName = Release;
426 | };
427 | /* End XCConfigurationList section */
428 | };
429 | rootObject = 7710F4E9176DE33900771BA7 /* Project object */;
430 | }
431 |
--------------------------------------------------------------------------------
/KLSwitch/KLSwitch/KLSwitch.m:
--------------------------------------------------------------------------------
1 | //
2 | // KLSwitch.m
3 | // KLSwitch
4 | //
5 | // Created by Kieran Lafferty on 2013-06-15.
6 | // Copyright (c) 2013 Kieran Lafferty. All rights reserved.
7 | //
8 | // https://github.com/KieranLafferty/KLSwitch
9 |
10 | #import "KLSwitch.h"
11 |
12 | #define kConstrainsFrameToProportions YES
13 | #define kHeightWidthRatio 1.6451612903 //Magic number as a result of dividing the height by the width on the default UISwitch size (51/31)
14 |
15 | //NSCoding Keys
16 | #define kCodingOnKey @"on"
17 | #define kCodingLockedKey @"off"
18 | #define kCodingOnTintColorKey @"onColor"
19 | #define kCodingOnColorKey @"onTintColor" //Not implemented
20 | #define kCodingTintColorKey @"tintColor"
21 | #define kCodingThumbTintColorKey @"thumbTintColor"
22 | #define kCodingOnImageKey @"onImage"
23 | #define kCodingOffImageKey @"offImage"
24 | #define kCodingConstrainFrameKey @"constrainFrame"
25 |
26 | //Appearance Defaults - Colors
27 | //Track Colors
28 | #define kDefaultTrackOnColor [UIColor colorWithRed:83/255.0 green: 214/255.0 blue: 105/255.0 alpha: 1]
29 | #define kDefaultTrackOffColor [UIColor colorWithWhite: 0.9f alpha:1.0f]
30 | #define kDefaultTrackContrastColor [UIColor whiteColor]
31 |
32 | //Thumb Colors
33 | #define kDefaultThumbTintColor [UIColor whiteColor]
34 | #define kDefaultThumbBorderColor [UIColor colorWithWhite: 0.9f alpha:1.0f]
35 |
36 | //Appearance - Layout
37 |
38 | //Size of knob with respect to the control - Must be a multiple of 2
39 | #define kThumbOffset 1
40 | #define kThumbTrackingGrowthRatio 1.2f //Amount to grow the thumb on press down
41 |
42 | #define kDefaultPanActivationThreshold 0.7 //Number between 0.0 - 1.0 describing how far user must drag before initiating the switch
43 |
44 | //Appearance - Animations
45 | #define kDefaultAnimationSlideLength 0.25f //Length of time to slide the thumb from left/right to right/left
46 | #define kDefaultAnimationScaleLength 0.15f //Length of time for the thumb to grow on press down
47 | #define kDefaultAnimationContrastResizeLength 0.25f //Length of time for the thumb to grow on press down
48 |
49 | #define kSwitchTrackContrastViewShrinkFactor 0.0001f //Must be very low but not 0 or else causes iOS 5 issues
50 |
51 | typedef enum {
52 | KLSwitchThumbJustifyLeft,
53 | KLSwitchThumbJustifyRight
54 | } KLSwitchThumbJustify;
55 |
56 | @interface KLSwitchThumb : UIView
57 | @property (nonatomic, assign) BOOL isTracking;
58 | -(void) growThumbWithJustification:(KLSwitchThumbJustify) justification;
59 | -(void) shrinkThumbWithJustification:(KLSwitchThumbJustify) justification;
60 | @end
61 |
62 | @interface KLSwitchTrack : UIView
63 | @property(nonatomic, getter=isOn) BOOL on;
64 | @property (nonatomic, strong) UIColor* contrastColor;
65 | @property (nonatomic, strong) UIColor* onTintColor;
66 | @property (nonatomic, strong) UIColor* tintColor;
67 | -(id) initWithFrame:(CGRect)frame
68 | onColor:(UIColor*) onColor
69 | offColor:(UIColor*) offColor
70 | contrastColor:(UIColor*) contrastColor;
71 | -(void) growContrastView;
72 | -(void) shrinkContrastView;
73 | -(void) setOn:(BOOL) on
74 | animated:(BOOL) animated;
75 | @end
76 |
77 |
78 | @interface KLSwitch ()
79 | @property (nonatomic, strong) KLSwitchTrack* track;
80 | @property (nonatomic, strong) KLSwitchThumb* thumb;
81 |
82 | //Gesture Recognizers
83 | @property (nonatomic, strong) UIPanGestureRecognizer* panGesture;
84 | @property (nonatomic, strong) UITapGestureRecognizer* tapGesture;
85 | -(void) configureSwitch;
86 | -(void) initializeDefaults;
87 | -(void) toggleState;
88 | -(void) setThumbOn:(BOOL) on
89 | animated:(BOOL) animated;
90 |
91 | @end
92 |
93 | @implementation KLSwitch
94 |
95 | #pragma mark - Initializers
96 |
97 | - (void)encodeWithCoder:(NSCoder *)aCoder {
98 | [super encodeWithCoder: aCoder];
99 |
100 | [aCoder encodeBool: _on
101 | forKey: kCodingOnKey];
102 |
103 | [aCoder encodeObject: _onTintColor
104 | forKey: kCodingOnTintColorKey];
105 |
106 | [aCoder encodeObject: _tintColor
107 | forKey: kCodingTintColorKey];
108 |
109 | [aCoder encodeObject: _thumbTintColor
110 | forKey: kCodingThumbTintColorKey];
111 |
112 | [aCoder encodeObject: _onImage
113 | forKey: kCodingOnImageKey];
114 |
115 | [aCoder encodeObject: _offImage
116 | forKey: kCodingOffImageKey];
117 |
118 | [aCoder encodeBool: _shouldConstrainFrame
119 | forKey: kCodingConstrainFrameKey];
120 |
121 | }
122 |
123 | - (id)initWithCoder:(NSCoder *)aDecoder {
124 | [self initializeDefaults];
125 | if (self = [super initWithCoder: aDecoder]) {
126 |
127 | _on = [aDecoder decodeBoolForKey:kCodingOnKey];
128 | _locked = [aDecoder decodeBoolForKey:kCodingLockedKey];
129 | _onTintColor = [aDecoder decodeObjectForKey: kCodingOnTintColorKey];
130 | _tintColor = [aDecoder decodeObjectForKey: kCodingTintColorKey];
131 | _thumbTintColor = [aDecoder decodeObjectForKey: kCodingThumbTintColorKey];
132 | _onImage = [aDecoder decodeObjectForKey: kCodingOnImageKey];
133 | _offImage = [aDecoder decodeObjectForKey: kCodingOffImageKey];
134 | _onTintColor = [aDecoder decodeObjectForKey: kCodingOnTintColorKey];
135 | _shouldConstrainFrame = [aDecoder decodeBoolForKey: kCodingConstrainFrameKey];
136 |
137 | [self configureSwitch];
138 |
139 | }
140 | return self;
141 | }
142 | - (id)initWithFrame:(CGRect)frame
143 | {
144 | self = [super initWithFrame:frame];
145 | if (self) {
146 | [self configureSwitch];
147 | }
148 | return self;
149 | }
150 | - (id)initWithFrame:(CGRect)frame
151 | didChangeHandler:(changeHandler) didChangeHandler {
152 | if (self = [self initWithFrame: frame]) {
153 | _didChangeHandler = didChangeHandler;
154 | }
155 | return self;
156 | }
157 | -(void) setFrame:(CGRect)frame {
158 | if (self.shouldConstrainFrame) {
159 | [super setFrame: CGRectMake(frame.origin.x, frame.origin.y, frame.size.height*kHeightWidthRatio, frame.size.height)];
160 | }
161 | else [super setFrame: frame];
162 | }
163 |
164 | #pragma mark - Defaults and layout/appearance
165 |
166 | -(void) initializeDefaults {
167 | _onTintColor = kDefaultTrackOnColor;
168 | _tintColor = kDefaultTrackOffColor;
169 | _thumbTintColor = kDefaultThumbTintColor;
170 | _thumbBorderColor = kDefaultThumbBorderColor;
171 | _contrastColor = kDefaultThumbTintColor;
172 | _panActivationThreshold = kDefaultPanActivationThreshold;
173 | _shouldConstrainFrame = kConstrainsFrameToProportions;
174 | }
175 | -(void) configureSwitch {
176 | [self initializeDefaults];
177 |
178 | //Configure visual properties of self
179 | [self setBackgroundColor: [UIColor clearColor]];
180 |
181 |
182 | // tap gesture for toggling the switch
183 | self.tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self
184 | action:@selector(didTap:)];
185 | [self.tapGesture setDelegate:self];
186 | [self addGestureRecognizer:self.tapGesture];
187 |
188 |
189 | // pan gesture for moving the switch knob manually
190 | self.panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self
191 | action:@selector(didDrag:)];
192 | [self.panGesture setDelegate:self];
193 | [self addGestureRecognizer:self.panGesture];
194 |
195 | /*
196 | Subview layering as follows :
197 |
198 | TOP
199 | thumb
200 | track
201 | BOTTOM
202 | */
203 | // Initialization code
204 | if (!_track) {
205 | _track = [[KLSwitchTrack alloc] initWithFrame: self.bounds
206 | onColor: self.onTintColor
207 | offColor: self.tintColor
208 | contrastColor: self.contrastColor];
209 | [_track setOn: self.isOn
210 | animated: NO];
211 | [self addSubview: self.track];
212 | }
213 | if (!_thumb) {
214 | _thumb = [[KLSwitchThumb alloc] initWithFrame:CGRectMake(kThumbOffset, kThumbOffset, self.bounds.size.height - 2 * kThumbOffset, self.bounds.size.height - 2 * kThumbOffset)];
215 | [self addSubview: _thumb];
216 | }
217 | }
218 |
219 | -(void) setOnTintColor:(UIColor *)onTintColor {
220 | _onTintColor = onTintColor;
221 | [self.track setOnTintColor: _onTintColor];
222 | }
223 | -(void) setTintColor:(UIColor *)tintColor {
224 | _tintColor = tintColor;
225 | [self.track setTintColor: _tintColor];
226 | }
227 | -(void) setContrastColor:(UIColor *)contrastColor {
228 | _contrastColor = contrastColor;
229 | [self.track setContrastColor: _contrastColor];
230 | }
231 | -(void) setThumbBorderColor:(UIColor *)thumbBorderColor {
232 | _thumbBorderColor = thumbBorderColor;
233 | [self.thumb.layer setBorderColor: [_thumbBorderColor CGColor]];
234 | }
235 | - (void)drawRect:(CGRect)rect
236 | {
237 | [super drawRect:rect];
238 | // Drawing code
239 | //[self.trackingKnob setTintColor: self.thumbTintColor];
240 | [_thumb setBackgroundColor: [UIColor whiteColor]];
241 |
242 | //Make the knob a circle and add a shadow
243 | CGFloat roundedCornerRadius = _thumb.frame.size.height/2.0f;
244 | [_thumb.layer setBorderWidth: 0.5];
245 | [_thumb.layer setBorderColor: [self.thumbBorderColor CGColor]];
246 | [_thumb.layer setCornerRadius: roundedCornerRadius];
247 | [_thumb.layer setShadowColor: [[UIColor grayColor] CGColor]];
248 | [_thumb.layer setShadowOffset: CGSizeMake(0, 3)];
249 | [_thumb.layer setShadowOpacity: 0.40f];
250 | [_thumb.layer setShadowRadius: 0.8];
251 | }
252 |
253 | #pragma mark - UIGestureRecognizer implementations
254 | -(void) didTap:(UITapGestureRecognizer*) gesture {
255 | if (gesture.state == UIGestureRecognizerStateEnded) {
256 | [self toggleState];
257 | }
258 | }
259 | -(void) didDrag:(UIPanGestureRecognizer*) gesture {
260 | if (gesture.state == UIGestureRecognizerStateBegan) {
261 | //Grow the thumb horizontally towards center by defined ratio
262 | [self setThumbIsTracking: YES
263 | animated: YES];
264 | }
265 | else if (gesture.state == UIGestureRecognizerStateChanged) {
266 | //If touch crosses the threshold then toggle the state
267 | CGPoint locationInThumb = [gesture locationInView: self.thumb];
268 |
269 | //Toggle the switch if the user pans left or right past the switch thumb bounds
270 | if ((self.isOn && locationInThumb.x <= 0)
271 | || (!self.isOn && locationInThumb.x >= self.thumb.bounds.size.width)) {
272 | [self toggleState];
273 | }
274 |
275 | CGPoint locationOfTouch = [gesture locationInView:self];
276 | if (CGRectContainsPoint(self.bounds, locationOfTouch))
277 | [self sendActionsForControlEvents:UIControlEventTouchDragInside];
278 | else
279 | [self sendActionsForControlEvents:UIControlEventTouchDragOutside];
280 | }
281 | else if (gesture.state == UIGestureRecognizerStateEnded) {
282 | [self setThumbIsTracking: NO
283 | animated: YES];
284 | }
285 | }
286 |
287 | #pragma mark - Event Handlers
288 |
289 | -(void) toggleState {
290 | //Alternate between on/off
291 | [self setOn: self.isOn ? NO : YES
292 | animated: YES];
293 | }
294 |
295 | - (void)setOn:(BOOL)on
296 | animated:(BOOL)animated {
297 | //Cancel notification to parent if attempting to set to current state
298 | if (_on == on) {
299 | return;
300 | }
301 |
302 | //Move the thumb to the new position
303 | [self setThumbOn: on
304 | animated: animated];
305 |
306 | //Animate the contrast view of the track
307 | [self.track setOn: on
308 | animated: animated];
309 |
310 | _on = on;
311 |
312 | //Trigger the completion block if exists
313 | if (self.didChangeHandler) {
314 | self.didChangeHandler(_on);
315 | }
316 | [self sendActionsForControlEvents:UIControlEventValueChanged];
317 | }
318 |
319 | - (void) setOn:(BOOL)on {
320 | [self setOn: on animated: NO];
321 | }
322 |
323 | - (void) setLocked:(BOOL)locked {
324 | //Cancel notification to parent if attempting to set to current state
325 | if (_locked == locked) {
326 | return;
327 | }
328 | _locked = locked;
329 |
330 | UIImageView *lockImageView = (UIImageView *)[_track viewWithTag:LOCK_IMAGE_SUBVIEW];
331 |
332 | if (!locked && (lockImageView != nil)) {
333 |
334 | [lockImageView removeFromSuperview];
335 | lockImageView = nil;
336 |
337 | } else if (locked && (lockImageView == nil)) {
338 |
339 | UIImage *lockImage = [UIImage imageNamed:@"lock-icon.png"];
340 |
341 | lockImageView = [[UIImageView alloc] initWithImage:lockImage];
342 |
343 | lockImageView.frame = CGRectMake(7, 8, lockImage.size.width, lockImage.size.height);
344 | lockImageView.tag = LOCK_IMAGE_SUBVIEW;
345 |
346 | [_track addSubview:lockImageView];
347 | [_track bringSubviewToFront:lockImageView];
348 | }
349 | }
350 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
351 | {
352 | [super touchesBegan:touches withEvent:event];
353 | [self sendActionsForControlEvents:UIControlEventTouchDown];
354 | }
355 |
356 | - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
357 | {
358 | [super touchesEnded:touches withEvent:event];
359 | [self sendActionsForControlEvents:UIControlEventTouchUpInside];
360 | }
361 | - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
362 | {
363 | [super touchesCancelled:touches withEvent:event];
364 | [self sendActionsForControlEvents:UIControlEventTouchUpOutside];
365 | }
366 |
367 | -(void) setThumbIsTracking:(BOOL)isTracking {
368 | if (isTracking) {
369 | //Grow
370 | [self.thumb growThumbWithJustification: self.isOn ? KLSwitchThumbJustifyRight : KLSwitchThumbJustifyLeft];
371 | }
372 | else {
373 | //Shrink
374 | [self.thumb shrinkThumbWithJustification: self.isOn ? KLSwitchThumbJustifyRight : KLSwitchThumbJustifyLeft];
375 | }
376 | [self.thumb setIsTracking: isTracking];
377 | }
378 | -(void) setThumbIsTracking:(BOOL)isTracking
379 | animated:(BOOL) animated {
380 | __weak id weakSelf = self;
381 | [UIView animateWithDuration: kDefaultAnimationScaleLength
382 | delay: fabs(kDefaultAnimationSlideLength - kDefaultAnimationScaleLength)
383 | options: UIViewAnimationOptionCurveEaseOut
384 | animations: ^{
385 | [weakSelf setThumbIsTracking: isTracking];
386 | }
387 | completion:nil];
388 | }
389 | -(void) setThumbOn:(BOOL) on
390 | animated:(BOOL) animated {
391 | if (animated) {
392 | [UIView animateWithDuration:0.3 animations:^{
393 | [self setThumbOn:on animated:NO];
394 | }];
395 | }
396 | CGRect thumbFrame = self.thumb.frame;
397 | if (on) {
398 | thumbFrame.origin.x = self.bounds.size.width - (thumbFrame.size.width + kThumbOffset);
399 | }
400 | else {
401 | thumbFrame.origin.x = kThumbOffset;
402 | }
403 | [self.thumb setFrame: thumbFrame];
404 | }
405 | @end
406 |
407 |
408 | @implementation KLSwitchThumb
409 |
410 | -(void) growThumbWithJustification:(KLSwitchThumbJustify) justification {
411 | if (self.isTracking)
412 | return;
413 |
414 | CGRect thumbFrame = self.frame;
415 |
416 | CGFloat deltaWidth = self.frame.size.width * (kThumbTrackingGrowthRatio - 1);
417 | thumbFrame.size.width += deltaWidth;
418 | if (justification == KLSwitchThumbJustifyRight) {
419 | thumbFrame.origin.x -= deltaWidth;
420 | }
421 | [self setFrame: thumbFrame];
422 | }
423 | -(void) shrinkThumbWithJustification:(KLSwitchThumbJustify) justification {
424 | if (!self.isTracking)
425 | return;
426 |
427 | CGRect thumbFrame = self.frame;
428 |
429 | CGFloat deltaWidth = self.frame.size.width * (1 - 1 / (kThumbTrackingGrowthRatio));
430 | thumbFrame.size.width -= deltaWidth;
431 | if (justification == KLSwitchThumbJustifyRight) {
432 | thumbFrame.origin.x += deltaWidth;
433 | }
434 | [self setFrame: thumbFrame];
435 |
436 | }
437 | @end
438 |
439 | @interface KLSwitchTrack ()
440 | @property (nonatomic, strong) UIView* contrastView;
441 | @property (nonatomic, strong) UIView* onView;
442 | @end
443 |
444 | @implementation KLSwitchTrack
445 |
446 | -(id) initWithFrame:(CGRect)frame
447 | onColor:(UIColor*) onColor
448 | offColor:(UIColor*) offColor
449 | contrastColor:(UIColor*) contrastColor {
450 | if (self = [super initWithFrame: frame]) {
451 | _onTintColor = onColor;
452 | _tintColor = offColor;
453 |
454 | CGFloat cornerRadius = frame.size.height/2.0f;
455 | [self.layer setCornerRadius: cornerRadius];
456 | [self setBackgroundColor: _tintColor];
457 |
458 | CGRect contrastRect = frame;
459 | contrastRect.size.width = frame.size.width - 2*kThumbOffset;
460 | contrastRect.size.height = frame.size.height - 2*kThumbOffset;
461 | CGFloat contrastRadius = contrastRect.size.height/2.0f;
462 |
463 | _contrastView = [[UIView alloc] initWithFrame:contrastRect];
464 | [_contrastView setBackgroundColor: contrastColor];
465 | [_contrastView setCenter: self.center];
466 | [_contrastView.layer setCornerRadius: contrastRadius];
467 | [self addSubview: _contrastView];
468 |
469 | _onView = [[UIView alloc] initWithFrame:frame];
470 | [_onView setBackgroundColor: _onTintColor];
471 | [_onView setCenter: self.center];
472 | [_onView.layer setCornerRadius: cornerRadius];
473 | [self addSubview: _onView];
474 |
475 | }
476 | return self;
477 | }
478 |
479 | -(void) setOn:(BOOL)on {
480 | if (on) {
481 | [self.onView setAlpha: 1.0];
482 | [self shrinkContrastView];
483 | }
484 | else {
485 | [self.onView setAlpha: 0.0];
486 | [self growContrastView];
487 | }
488 | }
489 |
490 | -(void) setOn:(BOOL)on
491 | animated:(BOOL)animated {
492 | if (animated) {
493 | __weak id weakSelf = self;
494 | //First animate the color switch
495 | [UIView animateWithDuration: kDefaultAnimationContrastResizeLength
496 | delay: 0.0
497 | options: UIViewAnimationOptionCurveEaseOut
498 | animations:^{
499 | [weakSelf setOn: on
500 | animated: NO];
501 | }
502 | completion:nil];
503 | }
504 | else {
505 | [self setOn: on];
506 | }
507 | }
508 |
509 | -(void) setOnTintColor:(UIColor *)onTintColor {
510 | _onTintColor = onTintColor;
511 | [self.onView setBackgroundColor: _onTintColor];
512 | }
513 |
514 | -(void) setTintColor:(UIColor *)tintColor {
515 | _tintColor = tintColor;
516 | [self setBackgroundColor: _tintColor];
517 | }
518 |
519 | -(void) setContrastColor:(UIColor *)contrastColor {
520 | _contrastColor = contrastColor;
521 | [self.contrastView setBackgroundColor: _contrastColor];
522 | }
523 |
524 | -(void) growContrastView {
525 | //Start out with contrast view small and centered
526 | [self.contrastView setTransform: CGAffineTransformMakeScale(kSwitchTrackContrastViewShrinkFactor, kSwitchTrackContrastViewShrinkFactor)];
527 | [self.contrastView setTransform: CGAffineTransformMakeScale(1, 1)];
528 | }
529 |
530 | -(void) shrinkContrastView {
531 | //Start out with contrast view the size of the track
532 | [self.contrastView setTransform: CGAffineTransformMakeScale(1, 1)];
533 | [self.contrastView setTransform: CGAffineTransformMakeScale(kSwitchTrackContrastViewShrinkFactor, kSwitchTrackContrastViewShrinkFactor)];
534 | }
535 |
536 | @end
537 |
--------------------------------------------------------------------------------
/KLSwitchDemo.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 7710F532176DEAF200771BA7 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7710F531176DEAF200771BA7 /* UIKit.framework */; };
11 | 7710F534176DEAF200771BA7 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7710F533176DEAF200771BA7 /* Foundation.framework */; };
12 | 7710F536176DEAF200771BA7 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7710F535176DEAF200771BA7 /* CoreGraphics.framework */; };
13 | 7710F53C176DEAF200771BA7 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 7710F53A176DEAF200771BA7 /* InfoPlist.strings */; };
14 | 7710F53E176DEAF200771BA7 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 7710F53D176DEAF200771BA7 /* main.m */; };
15 | 7710F542176DEAF200771BA7 /* KLAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7710F541176DEAF200771BA7 /* KLAppDelegate.m */; };
16 | 7710F544176DEAF200771BA7 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 7710F543176DEAF200771BA7 /* Default.png */; };
17 | 7710F546176DEAF200771BA7 /* Default@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7710F545176DEAF200771BA7 /* Default@2x.png */; };
18 | 7710F548176DEAF200771BA7 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7710F547176DEAF200771BA7 /* Default-568h@2x.png */; };
19 | 7710F54B176DEAF200771BA7 /* MainStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7710F549176DEAF200771BA7 /* MainStoryboard.storyboard */; };
20 | 7710F54E176DEAF200771BA7 /* KLViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7710F54D176DEAF200771BA7 /* KLViewController.m */; };
21 | 7710F556176DEAF200771BA7 /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7710F555176DEAF200771BA7 /* SenTestingKit.framework */; };
22 | 7710F557176DEAF200771BA7 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7710F531176DEAF200771BA7 /* UIKit.framework */; };
23 | 7710F558176DEAF200771BA7 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7710F533176DEAF200771BA7 /* Foundation.framework */; };
24 | 7710F560176DEAF200771BA7 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 7710F55E176DEAF200771BA7 /* InfoPlist.strings */; };
25 | 7710F563176DEAF200771BA7 /* KLSwitchDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7710F562176DEAF200771BA7 /* KLSwitchDemoTests.m */; };
26 | 7710F577176DEB2600771BA7 /* libKLSwitch.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7710F572176DEB1700771BA7 /* libKLSwitch.a */; };
27 | /* End PBXBuildFile section */
28 |
29 | /* Begin PBXContainerItemProxy section */
30 | 7710F559176DEAF200771BA7 /* PBXContainerItemProxy */ = {
31 | isa = PBXContainerItemProxy;
32 | containerPortal = 7710F526176DEAF200771BA7 /* Project object */;
33 | proxyType = 1;
34 | remoteGlobalIDString = 7710F52D176DEAF200771BA7;
35 | remoteInfo = KLSwitchDemo;
36 | };
37 | 7710F571176DEB1700771BA7 /* PBXContainerItemProxy */ = {
38 | isa = PBXContainerItemProxy;
39 | containerPortal = 7710F56C176DEB1700771BA7 /* KLSwitch.xcodeproj */;
40 | proxyType = 2;
41 | remoteGlobalIDString = 7710F4F1176DE33900771BA7;
42 | remoteInfo = KLSwitch;
43 | };
44 | 7710F573176DEB1700771BA7 /* PBXContainerItemProxy */ = {
45 | isa = PBXContainerItemProxy;
46 | containerPortal = 7710F56C176DEB1700771BA7 /* KLSwitch.xcodeproj */;
47 | proxyType = 2;
48 | remoteGlobalIDString = 7710F502176DE33900771BA7;
49 | remoteInfo = KLSwitchTests;
50 | };
51 | 7710F575176DEB1E00771BA7 /* PBXContainerItemProxy */ = {
52 | isa = PBXContainerItemProxy;
53 | containerPortal = 7710F56C176DEB1700771BA7 /* KLSwitch.xcodeproj */;
54 | proxyType = 1;
55 | remoteGlobalIDString = 7710F4F0176DE33900771BA7;
56 | remoteInfo = KLSwitch;
57 | };
58 | /* End PBXContainerItemProxy section */
59 |
60 | /* Begin PBXFileReference section */
61 | 7710F52E176DEAF200771BA7 /* KLSwitchDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KLSwitchDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
62 | 7710F531176DEAF200771BA7 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
63 | 7710F533176DEAF200771BA7 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
64 | 7710F535176DEAF200771BA7 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
65 | 7710F539176DEAF200771BA7 /* KLSwitchDemo-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "KLSwitchDemo-Info.plist"; sourceTree = ""; };
66 | 7710F53B176DEAF200771BA7 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; };
67 | 7710F53D176DEAF200771BA7 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
68 | 7710F53F176DEAF200771BA7 /* KLSwitchDemo-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "KLSwitchDemo-Prefix.pch"; sourceTree = ""; };
69 | 7710F540176DEAF200771BA7 /* KLAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KLAppDelegate.h; sourceTree = ""; };
70 | 7710F541176DEAF200771BA7 /* KLAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KLAppDelegate.m; sourceTree = ""; };
71 | 7710F543176DEAF200771BA7 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = ""; };
72 | 7710F545176DEAF200771BA7 /* Default@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default@2x.png"; sourceTree = ""; };
73 | 7710F547176DEAF200771BA7 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; };
74 | 7710F54A176DEAF200771BA7 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/MainStoryboard.storyboard; sourceTree = ""; };
75 | 7710F54C176DEAF200771BA7 /* KLViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KLViewController.h; sourceTree = ""; };
76 | 7710F54D176DEAF200771BA7 /* KLViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KLViewController.m; sourceTree = ""; };
77 | 7710F554176DEAF200771BA7 /* KLSwitchDemoTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = KLSwitchDemoTests.octest; sourceTree = BUILT_PRODUCTS_DIR; };
78 | 7710F555176DEAF200771BA7 /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; };
79 | 7710F55D176DEAF200771BA7 /* KLSwitchDemoTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "KLSwitchDemoTests-Info.plist"; sourceTree = ""; };
80 | 7710F55F176DEAF200771BA7 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; };
81 | 7710F561176DEAF200771BA7 /* KLSwitchDemoTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KLSwitchDemoTests.h; sourceTree = ""; };
82 | 7710F562176DEAF200771BA7 /* KLSwitchDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KLSwitchDemoTests.m; sourceTree = ""; };
83 | 7710F56C176DEB1700771BA7 /* KLSwitch.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = KLSwitch.xcodeproj; path = KLSwitch/KLSwitch.xcodeproj; sourceTree = SOURCE_ROOT; };
84 | /* End PBXFileReference section */
85 |
86 | /* Begin PBXFrameworksBuildPhase section */
87 | 7710F52B176DEAF200771BA7 /* Frameworks */ = {
88 | isa = PBXFrameworksBuildPhase;
89 | buildActionMask = 2147483647;
90 | files = (
91 | 7710F577176DEB2600771BA7 /* libKLSwitch.a in Frameworks */,
92 | 7710F532176DEAF200771BA7 /* UIKit.framework in Frameworks */,
93 | 7710F534176DEAF200771BA7 /* Foundation.framework in Frameworks */,
94 | 7710F536176DEAF200771BA7 /* CoreGraphics.framework in Frameworks */,
95 | );
96 | runOnlyForDeploymentPostprocessing = 0;
97 | };
98 | 7710F550176DEAF200771BA7 /* Frameworks */ = {
99 | isa = PBXFrameworksBuildPhase;
100 | buildActionMask = 2147483647;
101 | files = (
102 | 7710F556176DEAF200771BA7 /* SenTestingKit.framework in Frameworks */,
103 | 7710F557176DEAF200771BA7 /* UIKit.framework in Frameworks */,
104 | 7710F558176DEAF200771BA7 /* Foundation.framework in Frameworks */,
105 | );
106 | runOnlyForDeploymentPostprocessing = 0;
107 | };
108 | /* End PBXFrameworksBuildPhase section */
109 |
110 | /* Begin PBXGroup section */
111 | 7710F525176DEAF200771BA7 = {
112 | isa = PBXGroup;
113 | children = (
114 | 7710F537176DEAF200771BA7 /* KLSwitchDemo */,
115 | 7710F55B176DEAF200771BA7 /* KLSwitchDemoTests */,
116 | 7710F530176DEAF200771BA7 /* Frameworks */,
117 | 7710F52F176DEAF200771BA7 /* Products */,
118 | );
119 | sourceTree = "";
120 | };
121 | 7710F52F176DEAF200771BA7 /* Products */ = {
122 | isa = PBXGroup;
123 | children = (
124 | 7710F52E176DEAF200771BA7 /* KLSwitchDemo.app */,
125 | 7710F554176DEAF200771BA7 /* KLSwitchDemoTests.octest */,
126 | );
127 | name = Products;
128 | sourceTree = "";
129 | };
130 | 7710F530176DEAF200771BA7 /* Frameworks */ = {
131 | isa = PBXGroup;
132 | children = (
133 | 7710F531176DEAF200771BA7 /* UIKit.framework */,
134 | 7710F533176DEAF200771BA7 /* Foundation.framework */,
135 | 7710F535176DEAF200771BA7 /* CoreGraphics.framework */,
136 | 7710F555176DEAF200771BA7 /* SenTestingKit.framework */,
137 | );
138 | name = Frameworks;
139 | sourceTree = "";
140 | };
141 | 7710F537176DEAF200771BA7 /* KLSwitchDemo */ = {
142 | isa = PBXGroup;
143 | children = (
144 | 7710F56C176DEB1700771BA7 /* KLSwitch.xcodeproj */,
145 | 7710F540176DEAF200771BA7 /* KLAppDelegate.h */,
146 | 7710F541176DEAF200771BA7 /* KLAppDelegate.m */,
147 | 7710F549176DEAF200771BA7 /* MainStoryboard.storyboard */,
148 | 7710F54C176DEAF200771BA7 /* KLViewController.h */,
149 | 7710F54D176DEAF200771BA7 /* KLViewController.m */,
150 | 7710F538176DEAF200771BA7 /* Supporting Files */,
151 | );
152 | path = KLSwitchDemo;
153 | sourceTree = "";
154 | };
155 | 7710F538176DEAF200771BA7 /* Supporting Files */ = {
156 | isa = PBXGroup;
157 | children = (
158 | 7710F539176DEAF200771BA7 /* KLSwitchDemo-Info.plist */,
159 | 7710F53A176DEAF200771BA7 /* InfoPlist.strings */,
160 | 7710F53D176DEAF200771BA7 /* main.m */,
161 | 7710F53F176DEAF200771BA7 /* KLSwitchDemo-Prefix.pch */,
162 | 7710F543176DEAF200771BA7 /* Default.png */,
163 | 7710F545176DEAF200771BA7 /* Default@2x.png */,
164 | 7710F547176DEAF200771BA7 /* Default-568h@2x.png */,
165 | );
166 | name = "Supporting Files";
167 | sourceTree = "";
168 | };
169 | 7710F55B176DEAF200771BA7 /* KLSwitchDemoTests */ = {
170 | isa = PBXGroup;
171 | children = (
172 | 7710F561176DEAF200771BA7 /* KLSwitchDemoTests.h */,
173 | 7710F562176DEAF200771BA7 /* KLSwitchDemoTests.m */,
174 | 7710F55C176DEAF200771BA7 /* Supporting Files */,
175 | );
176 | path = KLSwitchDemoTests;
177 | sourceTree = "";
178 | };
179 | 7710F55C176DEAF200771BA7 /* Supporting Files */ = {
180 | isa = PBXGroup;
181 | children = (
182 | 7710F55D176DEAF200771BA7 /* KLSwitchDemoTests-Info.plist */,
183 | 7710F55E176DEAF200771BA7 /* InfoPlist.strings */,
184 | );
185 | name = "Supporting Files";
186 | sourceTree = "";
187 | };
188 | 7710F56D176DEB1700771BA7 /* Products */ = {
189 | isa = PBXGroup;
190 | children = (
191 | 7710F572176DEB1700771BA7 /* libKLSwitch.a */,
192 | 7710F574176DEB1700771BA7 /* KLSwitchTests.octest */,
193 | );
194 | name = Products;
195 | sourceTree = "";
196 | };
197 | /* End PBXGroup section */
198 |
199 | /* Begin PBXNativeTarget section */
200 | 7710F52D176DEAF200771BA7 /* KLSwitchDemo */ = {
201 | isa = PBXNativeTarget;
202 | buildConfigurationList = 7710F566176DEAF200771BA7 /* Build configuration list for PBXNativeTarget "KLSwitchDemo" */;
203 | buildPhases = (
204 | 7710F52A176DEAF200771BA7 /* Sources */,
205 | 7710F52B176DEAF200771BA7 /* Frameworks */,
206 | 7710F52C176DEAF200771BA7 /* Resources */,
207 | );
208 | buildRules = (
209 | );
210 | dependencies = (
211 | 7710F576176DEB1E00771BA7 /* PBXTargetDependency */,
212 | );
213 | name = KLSwitchDemo;
214 | productName = KLSwitchDemo;
215 | productReference = 7710F52E176DEAF200771BA7 /* KLSwitchDemo.app */;
216 | productType = "com.apple.product-type.application";
217 | };
218 | 7710F553176DEAF200771BA7 /* KLSwitchDemoTests */ = {
219 | isa = PBXNativeTarget;
220 | buildConfigurationList = 7710F569176DEAF200771BA7 /* Build configuration list for PBXNativeTarget "KLSwitchDemoTests" */;
221 | buildPhases = (
222 | 7710F54F176DEAF200771BA7 /* Sources */,
223 | 7710F550176DEAF200771BA7 /* Frameworks */,
224 | 7710F551176DEAF200771BA7 /* Resources */,
225 | 7710F552176DEAF200771BA7 /* ShellScript */,
226 | );
227 | buildRules = (
228 | );
229 | dependencies = (
230 | 7710F55A176DEAF200771BA7 /* PBXTargetDependency */,
231 | );
232 | name = KLSwitchDemoTests;
233 | productName = KLSwitchDemoTests;
234 | productReference = 7710F554176DEAF200771BA7 /* KLSwitchDemoTests.octest */;
235 | productType = "com.apple.product-type.bundle";
236 | };
237 | /* End PBXNativeTarget section */
238 |
239 | /* Begin PBXProject section */
240 | 7710F526176DEAF200771BA7 /* Project object */ = {
241 | isa = PBXProject;
242 | attributes = {
243 | CLASSPREFIX = KL;
244 | LastUpgradeCheck = 0460;
245 | ORGANIZATIONNAME = "Kieran Lafferty";
246 | };
247 | buildConfigurationList = 7710F529176DEAF200771BA7 /* Build configuration list for PBXProject "KLSwitchDemo" */;
248 | compatibilityVersion = "Xcode 3.2";
249 | developmentRegion = English;
250 | hasScannedForEncodings = 0;
251 | knownRegions = (
252 | en,
253 | );
254 | mainGroup = 7710F525176DEAF200771BA7;
255 | productRefGroup = 7710F52F176DEAF200771BA7 /* Products */;
256 | projectDirPath = "";
257 | projectReferences = (
258 | {
259 | ProductGroup = 7710F56D176DEB1700771BA7 /* Products */;
260 | ProjectRef = 7710F56C176DEB1700771BA7 /* KLSwitch.xcodeproj */;
261 | },
262 | );
263 | projectRoot = "";
264 | targets = (
265 | 7710F52D176DEAF200771BA7 /* KLSwitchDemo */,
266 | 7710F553176DEAF200771BA7 /* KLSwitchDemoTests */,
267 | );
268 | };
269 | /* End PBXProject section */
270 |
271 | /* Begin PBXReferenceProxy section */
272 | 7710F572176DEB1700771BA7 /* libKLSwitch.a */ = {
273 | isa = PBXReferenceProxy;
274 | fileType = archive.ar;
275 | path = libKLSwitch.a;
276 | remoteRef = 7710F571176DEB1700771BA7 /* PBXContainerItemProxy */;
277 | sourceTree = BUILT_PRODUCTS_DIR;
278 | };
279 | 7710F574176DEB1700771BA7 /* KLSwitchTests.octest */ = {
280 | isa = PBXReferenceProxy;
281 | fileType = wrapper.cfbundle;
282 | path = KLSwitchTests.octest;
283 | remoteRef = 7710F573176DEB1700771BA7 /* PBXContainerItemProxy */;
284 | sourceTree = BUILT_PRODUCTS_DIR;
285 | };
286 | /* End PBXReferenceProxy section */
287 |
288 | /* Begin PBXResourcesBuildPhase section */
289 | 7710F52C176DEAF200771BA7 /* Resources */ = {
290 | isa = PBXResourcesBuildPhase;
291 | buildActionMask = 2147483647;
292 | files = (
293 | 7710F53C176DEAF200771BA7 /* InfoPlist.strings in Resources */,
294 | 7710F544176DEAF200771BA7 /* Default.png in Resources */,
295 | 7710F546176DEAF200771BA7 /* Default@2x.png in Resources */,
296 | 7710F548176DEAF200771BA7 /* Default-568h@2x.png in Resources */,
297 | 7710F54B176DEAF200771BA7 /* MainStoryboard.storyboard in Resources */,
298 | );
299 | runOnlyForDeploymentPostprocessing = 0;
300 | };
301 | 7710F551176DEAF200771BA7 /* Resources */ = {
302 | isa = PBXResourcesBuildPhase;
303 | buildActionMask = 2147483647;
304 | files = (
305 | 7710F560176DEAF200771BA7 /* InfoPlist.strings in Resources */,
306 | );
307 | runOnlyForDeploymentPostprocessing = 0;
308 | };
309 | /* End PBXResourcesBuildPhase section */
310 |
311 | /* Begin PBXShellScriptBuildPhase section */
312 | 7710F552176DEAF200771BA7 /* ShellScript */ = {
313 | isa = PBXShellScriptBuildPhase;
314 | buildActionMask = 2147483647;
315 | files = (
316 | );
317 | inputPaths = (
318 | );
319 | outputPaths = (
320 | );
321 | runOnlyForDeploymentPostprocessing = 0;
322 | shellPath = /bin/sh;
323 | shellScript = "# Run the unit tests in this test bundle.\n\"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests\"\n";
324 | };
325 | /* End PBXShellScriptBuildPhase section */
326 |
327 | /* Begin PBXSourcesBuildPhase section */
328 | 7710F52A176DEAF200771BA7 /* Sources */ = {
329 | isa = PBXSourcesBuildPhase;
330 | buildActionMask = 2147483647;
331 | files = (
332 | 7710F53E176DEAF200771BA7 /* main.m in Sources */,
333 | 7710F542176DEAF200771BA7 /* KLAppDelegate.m in Sources */,
334 | 7710F54E176DEAF200771BA7 /* KLViewController.m in Sources */,
335 | );
336 | runOnlyForDeploymentPostprocessing = 0;
337 | };
338 | 7710F54F176DEAF200771BA7 /* Sources */ = {
339 | isa = PBXSourcesBuildPhase;
340 | buildActionMask = 2147483647;
341 | files = (
342 | 7710F563176DEAF200771BA7 /* KLSwitchDemoTests.m in Sources */,
343 | );
344 | runOnlyForDeploymentPostprocessing = 0;
345 | };
346 | /* End PBXSourcesBuildPhase section */
347 |
348 | /* Begin PBXTargetDependency section */
349 | 7710F55A176DEAF200771BA7 /* PBXTargetDependency */ = {
350 | isa = PBXTargetDependency;
351 | target = 7710F52D176DEAF200771BA7 /* KLSwitchDemo */;
352 | targetProxy = 7710F559176DEAF200771BA7 /* PBXContainerItemProxy */;
353 | };
354 | 7710F576176DEB1E00771BA7 /* PBXTargetDependency */ = {
355 | isa = PBXTargetDependency;
356 | name = KLSwitch;
357 | targetProxy = 7710F575176DEB1E00771BA7 /* PBXContainerItemProxy */;
358 | };
359 | /* End PBXTargetDependency section */
360 |
361 | /* Begin PBXVariantGroup section */
362 | 7710F53A176DEAF200771BA7 /* InfoPlist.strings */ = {
363 | isa = PBXVariantGroup;
364 | children = (
365 | 7710F53B176DEAF200771BA7 /* en */,
366 | );
367 | name = InfoPlist.strings;
368 | sourceTree = "";
369 | };
370 | 7710F549176DEAF200771BA7 /* MainStoryboard.storyboard */ = {
371 | isa = PBXVariantGroup;
372 | children = (
373 | 7710F54A176DEAF200771BA7 /* en */,
374 | );
375 | name = MainStoryboard.storyboard;
376 | sourceTree = "";
377 | };
378 | 7710F55E176DEAF200771BA7 /* InfoPlist.strings */ = {
379 | isa = PBXVariantGroup;
380 | children = (
381 | 7710F55F176DEAF200771BA7 /* en */,
382 | );
383 | name = InfoPlist.strings;
384 | sourceTree = "";
385 | };
386 | /* End PBXVariantGroup section */
387 |
388 | /* Begin XCBuildConfiguration section */
389 | 7710F564176DEAF200771BA7 /* Debug */ = {
390 | isa = XCBuildConfiguration;
391 | buildSettings = {
392 | ALWAYS_SEARCH_USER_PATHS = NO;
393 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
394 | CLANG_CXX_LIBRARY = "libc++";
395 | CLANG_ENABLE_OBJC_ARC = YES;
396 | CLANG_WARN_CONSTANT_CONVERSION = YES;
397 | CLANG_WARN_EMPTY_BODY = YES;
398 | CLANG_WARN_ENUM_CONVERSION = YES;
399 | CLANG_WARN_INT_CONVERSION = YES;
400 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
401 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
402 | COPY_PHASE_STRIP = NO;
403 | GCC_C_LANGUAGE_STANDARD = gnu99;
404 | GCC_DYNAMIC_NO_PIC = NO;
405 | GCC_OPTIMIZATION_LEVEL = 0;
406 | GCC_PREPROCESSOR_DEFINITIONS = (
407 | "DEBUG=1",
408 | "$(inherited)",
409 | );
410 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
411 | GCC_WARN_ABOUT_RETURN_TYPE = YES;
412 | GCC_WARN_UNINITIALIZED_AUTOS = YES;
413 | GCC_WARN_UNUSED_VARIABLE = YES;
414 | IPHONEOS_DEPLOYMENT_TARGET = 5.0;
415 | ONLY_ACTIVE_ARCH = YES;
416 | SDKROOT = iphoneos;
417 | };
418 | name = Debug;
419 | };
420 | 7710F565176DEAF200771BA7 /* Release */ = {
421 | isa = XCBuildConfiguration;
422 | buildSettings = {
423 | ALWAYS_SEARCH_USER_PATHS = NO;
424 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
425 | CLANG_CXX_LIBRARY = "libc++";
426 | CLANG_ENABLE_OBJC_ARC = YES;
427 | CLANG_WARN_CONSTANT_CONVERSION = YES;
428 | CLANG_WARN_EMPTY_BODY = YES;
429 | CLANG_WARN_ENUM_CONVERSION = YES;
430 | CLANG_WARN_INT_CONVERSION = YES;
431 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
432 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
433 | COPY_PHASE_STRIP = YES;
434 | GCC_C_LANGUAGE_STANDARD = gnu99;
435 | GCC_WARN_ABOUT_RETURN_TYPE = YES;
436 | GCC_WARN_UNINITIALIZED_AUTOS = YES;
437 | GCC_WARN_UNUSED_VARIABLE = YES;
438 | IPHONEOS_DEPLOYMENT_TARGET = 5.0;
439 | OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
440 | SDKROOT = iphoneos;
441 | VALIDATE_PRODUCT = YES;
442 | };
443 | name = Release;
444 | };
445 | 7710F567176DEAF200771BA7 /* Debug */ = {
446 | isa = XCBuildConfiguration;
447 | buildSettings = {
448 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
449 | GCC_PREFIX_HEADER = "KLSwitchDemo/KLSwitchDemo-Prefix.pch";
450 | INFOPLIST_FILE = "KLSwitchDemo/KLSwitchDemo-Info.plist";
451 | IPHONEOS_DEPLOYMENT_TARGET = 5.0;
452 | PRODUCT_NAME = "$(TARGET_NAME)";
453 | WRAPPER_EXTENSION = app;
454 | };
455 | name = Debug;
456 | };
457 | 7710F568176DEAF200771BA7 /* Release */ = {
458 | isa = XCBuildConfiguration;
459 | buildSettings = {
460 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
461 | GCC_PREFIX_HEADER = "KLSwitchDemo/KLSwitchDemo-Prefix.pch";
462 | INFOPLIST_FILE = "KLSwitchDemo/KLSwitchDemo-Info.plist";
463 | IPHONEOS_DEPLOYMENT_TARGET = 5.0;
464 | PRODUCT_NAME = "$(TARGET_NAME)";
465 | WRAPPER_EXTENSION = app;
466 | };
467 | name = Release;
468 | };
469 | 7710F56A176DEAF200771BA7 /* Debug */ = {
470 | isa = XCBuildConfiguration;
471 | buildSettings = {
472 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/KLSwitchDemo.app/KLSwitchDemo";
473 | FRAMEWORK_SEARCH_PATHS = (
474 | "\"$(SDKROOT)/Developer/Library/Frameworks\"",
475 | "\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"",
476 | );
477 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
478 | GCC_PREFIX_HEADER = "KLSwitchDemo/KLSwitchDemo-Prefix.pch";
479 | INFOPLIST_FILE = "KLSwitchDemoTests/KLSwitchDemoTests-Info.plist";
480 | PRODUCT_NAME = "$(TARGET_NAME)";
481 | TEST_HOST = "$(BUNDLE_LOADER)";
482 | WRAPPER_EXTENSION = octest;
483 | };
484 | name = Debug;
485 | };
486 | 7710F56B176DEAF200771BA7 /* Release */ = {
487 | isa = XCBuildConfiguration;
488 | buildSettings = {
489 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/KLSwitchDemo.app/KLSwitchDemo";
490 | FRAMEWORK_SEARCH_PATHS = (
491 | "\"$(SDKROOT)/Developer/Library/Frameworks\"",
492 | "\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"",
493 | );
494 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
495 | GCC_PREFIX_HEADER = "KLSwitchDemo/KLSwitchDemo-Prefix.pch";
496 | INFOPLIST_FILE = "KLSwitchDemoTests/KLSwitchDemoTests-Info.plist";
497 | PRODUCT_NAME = "$(TARGET_NAME)";
498 | TEST_HOST = "$(BUNDLE_LOADER)";
499 | WRAPPER_EXTENSION = octest;
500 | };
501 | name = Release;
502 | };
503 | /* End XCBuildConfiguration section */
504 |
505 | /* Begin XCConfigurationList section */
506 | 7710F529176DEAF200771BA7 /* Build configuration list for PBXProject "KLSwitchDemo" */ = {
507 | isa = XCConfigurationList;
508 | buildConfigurations = (
509 | 7710F564176DEAF200771BA7 /* Debug */,
510 | 7710F565176DEAF200771BA7 /* Release */,
511 | );
512 | defaultConfigurationIsVisible = 0;
513 | defaultConfigurationName = Release;
514 | };
515 | 7710F566176DEAF200771BA7 /* Build configuration list for PBXNativeTarget "KLSwitchDemo" */ = {
516 | isa = XCConfigurationList;
517 | buildConfigurations = (
518 | 7710F567176DEAF200771BA7 /* Debug */,
519 | 7710F568176DEAF200771BA7 /* Release */,
520 | );
521 | defaultConfigurationIsVisible = 0;
522 | defaultConfigurationName = Release;
523 | };
524 | 7710F569176DEAF200771BA7 /* Build configuration list for PBXNativeTarget "KLSwitchDemoTests" */ = {
525 | isa = XCConfigurationList;
526 | buildConfigurations = (
527 | 7710F56A176DEAF200771BA7 /* Debug */,
528 | 7710F56B176DEAF200771BA7 /* Release */,
529 | );
530 | defaultConfigurationIsVisible = 0;
531 | defaultConfigurationName = Release;
532 | };
533 | /* End XCConfigurationList section */
534 | };
535 | rootObject = 7710F526176DEAF200771BA7 /* Project object */;
536 | }
537 |
--------------------------------------------------------------------------------