├── .gitignore ├── .swift-version ├── Images ├── Toggler.gif └── Toggler2.gif ├── LICENSE ├── Package.swift ├── README.md ├── Toggler.podspec ├── Toggler.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcshareddata │ └── xcschemes │ └── Toggler.xcscheme ├── Toggler ├── Info.plist ├── Toggler.h └── Toggler.swift └── TogglerDemo ├── AppDelegate.swift ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Base.lproj ├── LaunchScreen.xib └── Main.storyboard ├── Button.swift ├── Info.plist └── ViewController.swift /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | ## Playgrounds 32 | timeline.xctimeline 33 | playground.xcworkspace 34 | 35 | # Swift Package Manager 36 | # 37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 38 | # Packages/ 39 | # Package.pins 40 | .build/ 41 | 42 | # CocoaPods 43 | # 44 | # We recommend against adding the Pods directory to your .gitignore. However 45 | # you should judge for yourself, the pros and cons are mentioned at: 46 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 47 | # 48 | # Pods/ 49 | 50 | # Carthage 51 | # 52 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 53 | # Carthage/Checkouts 54 | 55 | Carthage/Build 56 | 57 | # fastlane 58 | # 59 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 60 | # screenshots whenever they are needed. 61 | # For more information about the recommended setup visit: 62 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 63 | 64 | fastlane/report.xml 65 | fastlane/Preview.html 66 | fastlane/screenshots 67 | fastlane/test_output 68 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 4.0 -------------------------------------------------------------------------------- /Images/Toggler.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/younatics/Toggler/658dfb3930e5b5b00e2f2ba8bac2ed220100e345/Images/Toggler.gif -------------------------------------------------------------------------------- /Images/Toggler2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/younatics/Toggler/658dfb3930e5b5b00e2f2ba8bac2ed220100e345/Images/Toggler2.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Seungyoun Yi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | import PackageDescription 2 | 3 | let package = Package( 4 | name: "Toggler" 5 | ) 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Toggler 2 | [![Version](https://img.shields.io/cocoapods/v/Toggler.svg?style=flat)](http://cocoapods.org/pods/Toggler) 3 | [![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) 4 | [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/younatics/Toggler/blob/master/LICENSE) 5 | [![Platform](https://img.shields.io/cocoapods/p/Toggler.svg?style=flat)](http://cocoapods.org/pods/Toggler) 6 | [![Swift 4.0](https://img.shields.io/badge/Swift-4.0-orange.svg?style=flat)](https://developer.apple.com/swift/) 7 | 8 | ## Intoduction 9 | 💡 don't further use `isSelected` to every button. use `Toggler` to simply control your buttons 10 | ![demo](Images/Toggler.gif) 11 | ![demo](Images/Toggler2.gif) 12 | 13 | #### Don't do like these any more 14 | ```Swift 15 | func buttonClicked(_ sender: UIButton) { 16 | switch sender.tag { 17 | case 0: 18 | button1.isSelected = true 19 | button2.isSelected = false 20 | button3.isSelected = false 21 | button4.isSelected = false 22 | button5.isSelected = false 23 | case 1: 24 | button1.isSelected = false 25 | button2.isSelected = true 26 | button3.isSelected = false 27 | button4.isSelected = false 28 | button5.isSelected = false 29 | case 2: 30 | button1.isSelected = false 31 | button2.isSelected = false 32 | button3.isSelected = true 33 | button4.isSelected = false 34 | button5.isSelected = false 35 | case 3: 36 | button1.isSelected = false 37 | button2.isSelected = false 38 | button3.isSelected = false 39 | button4.isSelected = true 40 | button5.isSelected = false 41 | case 4: 42 | button1.isSelected = false 43 | button2.isSelected = false 44 | button3.isSelected = false 45 | button4.isSelected = false 46 | button5.isSelected = true 47 | default: 48 | break 49 | } 50 | } 51 | ``` 52 | 53 | #### Use `Toggler` 54 | ```Swift 55 | func buttonClicked(_ sender: UIButton) { 56 | toggler.on(toggle: sender) 57 | } 58 | ``` 59 | ## Requirements 60 | 61 | `Toggler` is written in Swift 3. Compatible with iOS 8.0+ 62 | 63 | ## Installation 64 | 65 | ### Cocoapods 66 | 67 | Toggler is available through [CocoaPods](http://cocoapods.org). To install 68 | it, simply add the following line to your Podfile: 69 | 70 | ```ruby 71 | pod 'Toggler' 72 | ``` 73 | ### Carthage 74 | ``` 75 | github "younatics/Toggler" 76 | ``` 77 | 78 | ## Usage 79 | Init with `UIButton` or `UISwtich` and default index 80 | ```Swift 81 | toggler = Toggler(default: 0, togglers: [button1, button2, button3, button4, button5]) 82 | ``` 83 | 84 | Toggle button 85 | ```Swift 86 | toggler.on(toggle: sender) 87 | toggler.onAt(index: sender.tag) 88 | ``` 89 | 90 | Add more button 91 | ```Swift 92 | toggler.add(toggle: button6) 93 | ``` 94 | 95 | Remove button 96 | ```Swift 97 | toggler.remove(at: 5) 98 | ``` 99 | 100 | ## References 101 | #### Please tell me or make pull request if you use this library in your application :) 102 | 103 | ## Author 104 | [younatics](https://twitter.com/younatics) 105 | Twitter 106 | 107 | ## License 108 | Toggler is available under the MIT license. See the LICENSE file for more info. 109 | -------------------------------------------------------------------------------- /Toggler.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod lib lint YNDropDownMenu.podspec' to ensure this is a 3 | # valid spec before submitting. 4 | # 5 | # Any lines starting with a # are optional, but their use is encouraged 6 | # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | s.name = 'Toggler' 11 | s.version = '1.0.0' 12 | s.summary = 'Easiest way to select a button and off other buttons' 13 | 14 | s.description = <<-DESC 15 | Easiest usage of button, written in Swift 3. You can add buttons what you want to control. 16 | DESC 17 | 18 | s.homepage = 'https://github.com/younatics/Toggler' 19 | s.license = { :type => 'MIT', :file => 'LICENSE' } 20 | s.author = { "Seungyoun Yi" => "younatics@gmail.com" } 21 | 22 | s.source = { :git => 'https://github.com/younatics/Toggler.git', :tag => s.version.to_s } 23 | s.source_files = 'Toggler/*.swift' 24 | 25 | s.ios.deployment_target = '8.0' 26 | 27 | s.frameworks = 'UIKit' 28 | s.requires_arc = true 29 | end 30 | -------------------------------------------------------------------------------- /Toggler.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 1946DAA41F3989FB0077D2FD /* Toggler.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 19EF94971F370F5D00085BCA /* Toggler.framework */; }; 11 | 1946DAA51F3989FB0077D2FD /* Toggler.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 19EF94971F370F5D00085BCA /* Toggler.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 12 | 19EF949C1F370F5D00085BCA /* Toggler.h in Headers */ = {isa = PBXBuildFile; fileRef = 19EF949A1F370F5D00085BCA /* Toggler.h */; settings = {ATTRIBUTES = (Public, ); }; }; 13 | 19EF94A91F37100D00085BCA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19EF94A81F37100D00085BCA /* AppDelegate.swift */; }; 14 | 19EF94AB1F37100D00085BCA /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19EF94AA1F37100D00085BCA /* ViewController.swift */; }; 15 | 19EF94AE1F37100D00085BCA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 19EF94AC1F37100D00085BCA /* Main.storyboard */; }; 16 | 19EF94B01F37100D00085BCA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 19EF94AF1F37100D00085BCA /* Assets.xcassets */; }; 17 | 19EF94B91F37102900085BCA /* Toggler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19EF94B81F37102900085BCA /* Toggler.swift */; }; 18 | 19EF94BC1F3720EF00085BCA /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 19EF94BA1F3720EF00085BCA /* LaunchScreen.xib */; }; 19 | 19EF94BE1F37215C00085BCA /* Button.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19EF94BD1F37215C00085BCA /* Button.swift */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXContainerItemProxy section */ 23 | 1946DAA61F3989FB0077D2FD /* PBXContainerItemProxy */ = { 24 | isa = PBXContainerItemProxy; 25 | containerPortal = 19EF948E1F370F5D00085BCA /* Project object */; 26 | proxyType = 1; 27 | remoteGlobalIDString = 19EF94961F370F5D00085BCA; 28 | remoteInfo = Toggler; 29 | }; 30 | /* End PBXContainerItemProxy section */ 31 | 32 | /* Begin PBXCopyFilesBuildPhase section */ 33 | 1946DAA81F3989FB0077D2FD /* Embed Frameworks */ = { 34 | isa = PBXCopyFilesBuildPhase; 35 | buildActionMask = 2147483647; 36 | dstPath = ""; 37 | dstSubfolderSpec = 10; 38 | files = ( 39 | 1946DAA51F3989FB0077D2FD /* Toggler.framework in Embed Frameworks */, 40 | ); 41 | name = "Embed Frameworks"; 42 | runOnlyForDeploymentPostprocessing = 0; 43 | }; 44 | /* End PBXCopyFilesBuildPhase section */ 45 | 46 | /* Begin PBXFileReference section */ 47 | 19EF94971F370F5D00085BCA /* Toggler.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Toggler.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 48 | 19EF949A1F370F5D00085BCA /* Toggler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Toggler.h; sourceTree = ""; }; 49 | 19EF949B1F370F5D00085BCA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 50 | 19EF94A61F37100D00085BCA /* TogglerDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TogglerDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 51 | 19EF94A81F37100D00085BCA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 52 | 19EF94AA1F37100D00085BCA /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 53 | 19EF94AD1F37100D00085BCA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 54 | 19EF94AF1F37100D00085BCA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 55 | 19EF94B41F37100D00085BCA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 56 | 19EF94B81F37102900085BCA /* Toggler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Toggler.swift; sourceTree = ""; }; 57 | 19EF94BB1F3720EF00085BCA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 58 | 19EF94BD1F37215C00085BCA /* Button.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Button.swift; sourceTree = ""; }; 59 | /* End PBXFileReference section */ 60 | 61 | /* Begin PBXFrameworksBuildPhase section */ 62 | 19EF94931F370F5D00085BCA /* Frameworks */ = { 63 | isa = PBXFrameworksBuildPhase; 64 | buildActionMask = 2147483647; 65 | files = ( 66 | ); 67 | runOnlyForDeploymentPostprocessing = 0; 68 | }; 69 | 19EF94A31F37100D00085BCA /* Frameworks */ = { 70 | isa = PBXFrameworksBuildPhase; 71 | buildActionMask = 2147483647; 72 | files = ( 73 | 1946DAA41F3989FB0077D2FD /* Toggler.framework in Frameworks */, 74 | ); 75 | runOnlyForDeploymentPostprocessing = 0; 76 | }; 77 | /* End PBXFrameworksBuildPhase section */ 78 | 79 | /* Begin PBXGroup section */ 80 | 19EF948D1F370F5D00085BCA = { 81 | isa = PBXGroup; 82 | children = ( 83 | 19EF94991F370F5D00085BCA /* Toggler */, 84 | 19EF94A71F37100D00085BCA /* TogglerDemo */, 85 | 19EF94981F370F5D00085BCA /* Products */, 86 | ); 87 | sourceTree = ""; 88 | }; 89 | 19EF94981F370F5D00085BCA /* Products */ = { 90 | isa = PBXGroup; 91 | children = ( 92 | 19EF94971F370F5D00085BCA /* Toggler.framework */, 93 | 19EF94A61F37100D00085BCA /* TogglerDemo.app */, 94 | ); 95 | name = Products; 96 | sourceTree = ""; 97 | }; 98 | 19EF94991F370F5D00085BCA /* Toggler */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | 19EF94B81F37102900085BCA /* Toggler.swift */, 102 | 19EF949A1F370F5D00085BCA /* Toggler.h */, 103 | 19EF949B1F370F5D00085BCA /* Info.plist */, 104 | ); 105 | path = Toggler; 106 | sourceTree = ""; 107 | }; 108 | 19EF94A71F37100D00085BCA /* TogglerDemo */ = { 109 | isa = PBXGroup; 110 | children = ( 111 | 19EF94BA1F3720EF00085BCA /* LaunchScreen.xib */, 112 | 19EF94A81F37100D00085BCA /* AppDelegate.swift */, 113 | 19EF94AA1F37100D00085BCA /* ViewController.swift */, 114 | 19EF94BD1F37215C00085BCA /* Button.swift */, 115 | 19EF94AC1F37100D00085BCA /* Main.storyboard */, 116 | 19EF94AF1F37100D00085BCA /* Assets.xcassets */, 117 | 19EF94B41F37100D00085BCA /* Info.plist */, 118 | ); 119 | path = TogglerDemo; 120 | sourceTree = ""; 121 | }; 122 | /* End PBXGroup section */ 123 | 124 | /* Begin PBXHeadersBuildPhase section */ 125 | 19EF94941F370F5D00085BCA /* Headers */ = { 126 | isa = PBXHeadersBuildPhase; 127 | buildActionMask = 2147483647; 128 | files = ( 129 | 19EF949C1F370F5D00085BCA /* Toggler.h in Headers */, 130 | ); 131 | runOnlyForDeploymentPostprocessing = 0; 132 | }; 133 | /* End PBXHeadersBuildPhase section */ 134 | 135 | /* Begin PBXNativeTarget section */ 136 | 19EF94961F370F5D00085BCA /* Toggler */ = { 137 | isa = PBXNativeTarget; 138 | buildConfigurationList = 19EF949F1F370F5D00085BCA /* Build configuration list for PBXNativeTarget "Toggler" */; 139 | buildPhases = ( 140 | 19EF94921F370F5D00085BCA /* Sources */, 141 | 19EF94931F370F5D00085BCA /* Frameworks */, 142 | 19EF94941F370F5D00085BCA /* Headers */, 143 | 19EF94951F370F5D00085BCA /* Resources */, 144 | ); 145 | buildRules = ( 146 | ); 147 | dependencies = ( 148 | ); 149 | name = Toggler; 150 | productName = Toggler; 151 | productReference = 19EF94971F370F5D00085BCA /* Toggler.framework */; 152 | productType = "com.apple.product-type.framework"; 153 | }; 154 | 19EF94A51F37100D00085BCA /* TogglerDemo */ = { 155 | isa = PBXNativeTarget; 156 | buildConfigurationList = 19EF94B71F37100D00085BCA /* Build configuration list for PBXNativeTarget "TogglerDemo" */; 157 | buildPhases = ( 158 | 19EF94A21F37100D00085BCA /* Sources */, 159 | 19EF94A31F37100D00085BCA /* Frameworks */, 160 | 19EF94A41F37100D00085BCA /* Resources */, 161 | 1946DAA81F3989FB0077D2FD /* Embed Frameworks */, 162 | ); 163 | buildRules = ( 164 | ); 165 | dependencies = ( 166 | 1946DAA71F3989FB0077D2FD /* PBXTargetDependency */, 167 | ); 168 | name = TogglerDemo; 169 | productName = TogglerDemo; 170 | productReference = 19EF94A61F37100D00085BCA /* TogglerDemo.app */; 171 | productType = "com.apple.product-type.application"; 172 | }; 173 | /* End PBXNativeTarget section */ 174 | 175 | /* Begin PBXProject section */ 176 | 19EF948E1F370F5D00085BCA /* Project object */ = { 177 | isa = PBXProject; 178 | attributes = { 179 | LastSwiftUpdateCheck = 0830; 180 | LastUpgradeCheck = 0910; 181 | ORGANIZATIONNAME = SeungyounYi; 182 | TargetAttributes = { 183 | 19EF94961F370F5D00085BCA = { 184 | CreatedOnToolsVersion = 8.3.3; 185 | DevelopmentTeam = 4G7K3CN2JU; 186 | LastSwiftMigration = 0830; 187 | ProvisioningStyle = Automatic; 188 | }; 189 | 19EF94A51F37100D00085BCA = { 190 | CreatedOnToolsVersion = 8.3.3; 191 | DevelopmentTeam = 4G7K3CN2JU; 192 | ProvisioningStyle = Automatic; 193 | }; 194 | }; 195 | }; 196 | buildConfigurationList = 19EF94911F370F5D00085BCA /* Build configuration list for PBXProject "Toggler" */; 197 | compatibilityVersion = "Xcode 3.2"; 198 | developmentRegion = English; 199 | hasScannedForEncodings = 0; 200 | knownRegions = ( 201 | en, 202 | Base, 203 | ); 204 | mainGroup = 19EF948D1F370F5D00085BCA; 205 | productRefGroup = 19EF94981F370F5D00085BCA /* Products */; 206 | projectDirPath = ""; 207 | projectRoot = ""; 208 | targets = ( 209 | 19EF94961F370F5D00085BCA /* Toggler */, 210 | 19EF94A51F37100D00085BCA /* TogglerDemo */, 211 | ); 212 | }; 213 | /* End PBXProject section */ 214 | 215 | /* Begin PBXResourcesBuildPhase section */ 216 | 19EF94951F370F5D00085BCA /* Resources */ = { 217 | isa = PBXResourcesBuildPhase; 218 | buildActionMask = 2147483647; 219 | files = ( 220 | ); 221 | runOnlyForDeploymentPostprocessing = 0; 222 | }; 223 | 19EF94A41F37100D00085BCA /* Resources */ = { 224 | isa = PBXResourcesBuildPhase; 225 | buildActionMask = 2147483647; 226 | files = ( 227 | 19EF94B01F37100D00085BCA /* Assets.xcassets in Resources */, 228 | 19EF94BC1F3720EF00085BCA /* LaunchScreen.xib in Resources */, 229 | 19EF94AE1F37100D00085BCA /* Main.storyboard in Resources */, 230 | ); 231 | runOnlyForDeploymentPostprocessing = 0; 232 | }; 233 | /* End PBXResourcesBuildPhase section */ 234 | 235 | /* Begin PBXSourcesBuildPhase section */ 236 | 19EF94921F370F5D00085BCA /* Sources */ = { 237 | isa = PBXSourcesBuildPhase; 238 | buildActionMask = 2147483647; 239 | files = ( 240 | 19EF94B91F37102900085BCA /* Toggler.swift in Sources */, 241 | ); 242 | runOnlyForDeploymentPostprocessing = 0; 243 | }; 244 | 19EF94A21F37100D00085BCA /* Sources */ = { 245 | isa = PBXSourcesBuildPhase; 246 | buildActionMask = 2147483647; 247 | files = ( 248 | 19EF94AB1F37100D00085BCA /* ViewController.swift in Sources */, 249 | 19EF94BE1F37215C00085BCA /* Button.swift in Sources */, 250 | 19EF94A91F37100D00085BCA /* AppDelegate.swift in Sources */, 251 | ); 252 | runOnlyForDeploymentPostprocessing = 0; 253 | }; 254 | /* End PBXSourcesBuildPhase section */ 255 | 256 | /* Begin PBXTargetDependency section */ 257 | 1946DAA71F3989FB0077D2FD /* PBXTargetDependency */ = { 258 | isa = PBXTargetDependency; 259 | target = 19EF94961F370F5D00085BCA /* Toggler */; 260 | targetProxy = 1946DAA61F3989FB0077D2FD /* PBXContainerItemProxy */; 261 | }; 262 | /* End PBXTargetDependency section */ 263 | 264 | /* Begin PBXVariantGroup section */ 265 | 19EF94AC1F37100D00085BCA /* Main.storyboard */ = { 266 | isa = PBXVariantGroup; 267 | children = ( 268 | 19EF94AD1F37100D00085BCA /* Base */, 269 | ); 270 | name = Main.storyboard; 271 | sourceTree = ""; 272 | }; 273 | 19EF94BA1F3720EF00085BCA /* LaunchScreen.xib */ = { 274 | isa = PBXVariantGroup; 275 | children = ( 276 | 19EF94BB1F3720EF00085BCA /* Base */, 277 | ); 278 | name = LaunchScreen.xib; 279 | sourceTree = ""; 280 | }; 281 | /* End PBXVariantGroup section */ 282 | 283 | /* Begin XCBuildConfiguration section */ 284 | 19EF949D1F370F5D00085BCA /* Debug */ = { 285 | isa = XCBuildConfiguration; 286 | buildSettings = { 287 | ALWAYS_SEARCH_USER_PATHS = NO; 288 | CLANG_ANALYZER_NONNULL = YES; 289 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 290 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 291 | CLANG_CXX_LIBRARY = "libc++"; 292 | CLANG_ENABLE_MODULES = YES; 293 | CLANG_ENABLE_OBJC_ARC = YES; 294 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 295 | CLANG_WARN_BOOL_CONVERSION = YES; 296 | CLANG_WARN_COMMA = YES; 297 | CLANG_WARN_CONSTANT_CONVERSION = YES; 298 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 299 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 300 | CLANG_WARN_EMPTY_BODY = YES; 301 | CLANG_WARN_ENUM_CONVERSION = YES; 302 | CLANG_WARN_INFINITE_RECURSION = YES; 303 | CLANG_WARN_INT_CONVERSION = YES; 304 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 305 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 306 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 307 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 308 | CLANG_WARN_STRICT_PROTOTYPES = YES; 309 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 310 | CLANG_WARN_UNREACHABLE_CODE = YES; 311 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 312 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 313 | COPY_PHASE_STRIP = NO; 314 | CURRENT_PROJECT_VERSION = 1; 315 | DEBUG_INFORMATION_FORMAT = dwarf; 316 | ENABLE_STRICT_OBJC_MSGSEND = YES; 317 | ENABLE_TESTABILITY = YES; 318 | GCC_C_LANGUAGE_STANDARD = gnu99; 319 | GCC_DYNAMIC_NO_PIC = NO; 320 | GCC_NO_COMMON_BLOCKS = YES; 321 | GCC_OPTIMIZATION_LEVEL = 0; 322 | GCC_PREPROCESSOR_DEFINITIONS = ( 323 | "DEBUG=1", 324 | "$(inherited)", 325 | ); 326 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 327 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 328 | GCC_WARN_UNDECLARED_SELECTOR = YES; 329 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 330 | GCC_WARN_UNUSED_FUNCTION = YES; 331 | GCC_WARN_UNUSED_VARIABLE = YES; 332 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 333 | MTL_ENABLE_DEBUG_INFO = YES; 334 | ONLY_ACTIVE_ARCH = YES; 335 | SDKROOT = iphoneos; 336 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 337 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 338 | SWIFT_VERSION = 4.0; 339 | TARGETED_DEVICE_FAMILY = "1,2"; 340 | VERSIONING_SYSTEM = "apple-generic"; 341 | VERSION_INFO_PREFIX = ""; 342 | }; 343 | name = Debug; 344 | }; 345 | 19EF949E1F370F5D00085BCA /* Release */ = { 346 | isa = XCBuildConfiguration; 347 | buildSettings = { 348 | ALWAYS_SEARCH_USER_PATHS = NO; 349 | CLANG_ANALYZER_NONNULL = YES; 350 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 351 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 352 | CLANG_CXX_LIBRARY = "libc++"; 353 | CLANG_ENABLE_MODULES = YES; 354 | CLANG_ENABLE_OBJC_ARC = YES; 355 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 356 | CLANG_WARN_BOOL_CONVERSION = YES; 357 | CLANG_WARN_COMMA = YES; 358 | CLANG_WARN_CONSTANT_CONVERSION = YES; 359 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 360 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 361 | CLANG_WARN_EMPTY_BODY = YES; 362 | CLANG_WARN_ENUM_CONVERSION = YES; 363 | CLANG_WARN_INFINITE_RECURSION = YES; 364 | CLANG_WARN_INT_CONVERSION = YES; 365 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 366 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 367 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 368 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 369 | CLANG_WARN_STRICT_PROTOTYPES = YES; 370 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 371 | CLANG_WARN_UNREACHABLE_CODE = YES; 372 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 373 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 374 | COPY_PHASE_STRIP = NO; 375 | CURRENT_PROJECT_VERSION = 1; 376 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 377 | ENABLE_NS_ASSERTIONS = NO; 378 | ENABLE_STRICT_OBJC_MSGSEND = YES; 379 | GCC_C_LANGUAGE_STANDARD = gnu99; 380 | GCC_NO_COMMON_BLOCKS = YES; 381 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 382 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 383 | GCC_WARN_UNDECLARED_SELECTOR = YES; 384 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 385 | GCC_WARN_UNUSED_FUNCTION = YES; 386 | GCC_WARN_UNUSED_VARIABLE = YES; 387 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 388 | MTL_ENABLE_DEBUG_INFO = NO; 389 | SDKROOT = iphoneos; 390 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 391 | SWIFT_VERSION = 4.0; 392 | TARGETED_DEVICE_FAMILY = "1,2"; 393 | VALIDATE_PRODUCT = YES; 394 | VERSIONING_SYSTEM = "apple-generic"; 395 | VERSION_INFO_PREFIX = ""; 396 | }; 397 | name = Release; 398 | }; 399 | 19EF94A01F370F5D00085BCA /* Debug */ = { 400 | isa = XCBuildConfiguration; 401 | buildSettings = { 402 | CLANG_ENABLE_MODULES = YES; 403 | CODE_SIGN_IDENTITY = ""; 404 | DEFINES_MODULE = YES; 405 | DEVELOPMENT_TEAM = 4G7K3CN2JU; 406 | DYLIB_COMPATIBILITY_VERSION = 1; 407 | DYLIB_CURRENT_VERSION = 1; 408 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 409 | INFOPLIST_FILE = Toggler/Info.plist; 410 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 411 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 412 | PRODUCT_BUNDLE_IDENTIFIER = com.seungyounyi.Toggler; 413 | PRODUCT_NAME = "$(TARGET_NAME)"; 414 | SKIP_INSTALL = YES; 415 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 416 | SWIFT_VERSION = 4.0; 417 | }; 418 | name = Debug; 419 | }; 420 | 19EF94A11F370F5D00085BCA /* Release */ = { 421 | isa = XCBuildConfiguration; 422 | buildSettings = { 423 | CLANG_ENABLE_MODULES = YES; 424 | CODE_SIGN_IDENTITY = ""; 425 | DEFINES_MODULE = YES; 426 | DEVELOPMENT_TEAM = 4G7K3CN2JU; 427 | DYLIB_COMPATIBILITY_VERSION = 1; 428 | DYLIB_CURRENT_VERSION = 1; 429 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 430 | INFOPLIST_FILE = Toggler/Info.plist; 431 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 432 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 433 | PRODUCT_BUNDLE_IDENTIFIER = com.seungyounyi.Toggler; 434 | PRODUCT_NAME = "$(TARGET_NAME)"; 435 | SKIP_INSTALL = YES; 436 | SWIFT_VERSION = 4.0; 437 | }; 438 | name = Release; 439 | }; 440 | 19EF94B51F37100D00085BCA /* Debug */ = { 441 | isa = XCBuildConfiguration; 442 | buildSettings = { 443 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 444 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 445 | DEVELOPMENT_TEAM = 4G7K3CN2JU; 446 | INFOPLIST_FILE = TogglerDemo/Info.plist; 447 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 448 | PRODUCT_BUNDLE_IDENTIFIER = com.seungyounyi.TogglerDemo; 449 | PRODUCT_NAME = "$(TARGET_NAME)"; 450 | SWIFT_VERSION = 4.0; 451 | }; 452 | name = Debug; 453 | }; 454 | 19EF94B61F37100D00085BCA /* Release */ = { 455 | isa = XCBuildConfiguration; 456 | buildSettings = { 457 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 458 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 459 | DEVELOPMENT_TEAM = 4G7K3CN2JU; 460 | INFOPLIST_FILE = TogglerDemo/Info.plist; 461 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 462 | PRODUCT_BUNDLE_IDENTIFIER = com.seungyounyi.TogglerDemo; 463 | PRODUCT_NAME = "$(TARGET_NAME)"; 464 | SWIFT_VERSION = 4.0; 465 | }; 466 | name = Release; 467 | }; 468 | /* End XCBuildConfiguration section */ 469 | 470 | /* Begin XCConfigurationList section */ 471 | 19EF94911F370F5D00085BCA /* Build configuration list for PBXProject "Toggler" */ = { 472 | isa = XCConfigurationList; 473 | buildConfigurations = ( 474 | 19EF949D1F370F5D00085BCA /* Debug */, 475 | 19EF949E1F370F5D00085BCA /* Release */, 476 | ); 477 | defaultConfigurationIsVisible = 0; 478 | defaultConfigurationName = Release; 479 | }; 480 | 19EF949F1F370F5D00085BCA /* Build configuration list for PBXNativeTarget "Toggler" */ = { 481 | isa = XCConfigurationList; 482 | buildConfigurations = ( 483 | 19EF94A01F370F5D00085BCA /* Debug */, 484 | 19EF94A11F370F5D00085BCA /* Release */, 485 | ); 486 | defaultConfigurationIsVisible = 0; 487 | defaultConfigurationName = Release; 488 | }; 489 | 19EF94B71F37100D00085BCA /* Build configuration list for PBXNativeTarget "TogglerDemo" */ = { 490 | isa = XCConfigurationList; 491 | buildConfigurations = ( 492 | 19EF94B51F37100D00085BCA /* Debug */, 493 | 19EF94B61F37100D00085BCA /* Release */, 494 | ); 495 | defaultConfigurationIsVisible = 0; 496 | defaultConfigurationName = Release; 497 | }; 498 | /* End XCConfigurationList section */ 499 | }; 500 | rootObject = 19EF948E1F370F5D00085BCA /* Project object */; 501 | } 502 | -------------------------------------------------------------------------------- /Toggler.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Toggler.xcodeproj/xcshareddata/xcschemes/Toggler.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 33 | 34 | 35 | 36 | 47 | 48 | 54 | 55 | 56 | 57 | 58 | 59 | 65 | 66 | 72 | 73 | 74 | 75 | 77 | 78 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /Toggler/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSPrincipalClass 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Toggler/Toggler.h: -------------------------------------------------------------------------------- 1 | // 2 | // Toggler.h 3 | // Toggler 4 | // 5 | // Created by YiSeungyoun on 2017. 8. 6.. 6 | // Copyright © 2017년 SeungyounYi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for Toggler. 12 | FOUNDATION_EXPORT double TogglerVersionNumber; 13 | 14 | //! Project version string for Toggler. 15 | FOUNDATION_EXPORT const unsigned char TogglerVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /Toggler/Toggler.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Toggler.swift 3 | // Toggler 4 | // 5 | // Created by YiSeungyoun on 2017. 8. 6.. 6 | // Copyright © 2017년 SeungyounYi. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | public protocol Togglable: class { 13 | func selectedToggle(select: Bool) 14 | } 15 | 16 | extension UIControl: Togglable { 17 | @objc public func selectedToggle(select: Bool) { 18 | isSelected = select 19 | } 20 | } 21 | 22 | extension UISwitch { 23 | public override func selectedToggle(select: Bool) { 24 | setOn(select, animated: true) 25 | } 26 | } 27 | 28 | public struct Toggler { 29 | var togglers = [Togglable]() 30 | 31 | public init(default index: Int = 0, togglers: [Togglable]) { 32 | self.togglers = togglers 33 | toggleControl(toggle: togglers[index], togglers: togglers) 34 | } 35 | 36 | public func on(toggle: Togglable) { 37 | toggleControl(toggle: toggle, togglers: togglers) 38 | } 39 | 40 | public func onAt(index: Int) { 41 | toggleControl(toggle: togglers[index], togglers: togglers) 42 | } 43 | 44 | public mutating func add(toggle: Togglable) { 45 | togglers.append(toggle) 46 | } 47 | 48 | public mutating func remove(at index: Int) { 49 | guard index < togglers.count else { 50 | fatalError("Index is out of array") 51 | } 52 | togglers.remove(at: index) 53 | } 54 | 55 | private func toggleControl(toggle: Togglable, togglers: [Togglable]) { 56 | togglers.enumerated().forEach { 57 | toggleStatus(toggle: $0.element, on: $0.element === toggle) 58 | } 59 | } 60 | 61 | private func toggleStatus(toggle: Togglable, on: Bool) { 62 | toggle.selectedToggle(select: on) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /TogglerDemo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // TogglerDemo 4 | // 5 | // Created by YiSeungyoun on 2017. 8. 6.. 6 | // Copyright © 2017년 SeungyounYi. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // 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. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // 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. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // 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. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /TogglerDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | } 88 | ], 89 | "info" : { 90 | "version" : 1, 91 | "author" : "xcode" 92 | } 93 | } -------------------------------------------------------------------------------- /TogglerDemo/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 25 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /TogglerDemo/Base.lproj/Main.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 | 34 | 43 | 52 | 61 | 70 | 79 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /TogglerDemo/Button.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Button.swift 3 | // Toggler 4 | // 5 | // Created by YiSeungyoun on 2017. 8. 6.. 6 | // Copyright © 2017년 SeungyounYi. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class Button: UIButton { 12 | override func awakeFromNib() { 13 | super.awakeFromNib() 14 | } 15 | 16 | override var isSelected: Bool { 17 | didSet { 18 | if isSelected { 19 | changed() 20 | } else { 21 | normal() 22 | } 23 | } 24 | } 25 | 26 | func changed() { 27 | self.setTitle("Selected", for: .normal) 28 | self.backgroundColor = UIColor.lightGray 29 | } 30 | 31 | func normal() { 32 | self.setTitle("Normal", for: .normal) 33 | self.backgroundColor = UIColor.white 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /TogglerDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /TogglerDemo/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // TogglerDemo 4 | // 5 | // Created by YiSeungyoun on 2017. 8. 6.. 6 | // Copyright © 2017년 SeungyounYi. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import Toggler 11 | 12 | class ViewController: UIViewController { 13 | var toggler: Toggler! 14 | var toggler2: Toggler! 15 | 16 | @IBOutlet weak var button1: Button! 17 | @IBOutlet weak var button2: Button! 18 | @IBOutlet weak var button3: Button! 19 | @IBOutlet weak var button4: Button! 20 | @IBOutlet weak var button5: Button! 21 | 22 | @IBOutlet weak var button6: Button! 23 | @IBOutlet weak var button7: Button! 24 | @IBOutlet weak var button8: Button! 25 | @IBOutlet weak var button9: UIControl! 26 | @IBOutlet weak var button10: UIControl! 27 | 28 | override func viewDidLoad() { 29 | super.viewDidLoad() 30 | 31 | toggler = Toggler(default: 0, togglers: [button1, button2, button3, button4, button5]) 32 | button1.addTarget(self, action: #selector(buttonClicked(_:)), for: .touchUpInside) 33 | button1.tag = 0 34 | 35 | button2.addTarget(self, action: #selector(buttonClicked(_:)), for: .touchUpInside) 36 | button2.tag = 1 37 | 38 | button3.addTarget(self, action: #selector(buttonClicked(_:)), for: .touchUpInside) 39 | button3.tag = 2 40 | 41 | button4.addTarget(self, action: #selector(buttonClicked(_:)), for: .touchUpInside) 42 | button4.tag = 3 43 | 44 | button5.addTarget(self, action: #selector(buttonClicked(_:)), for: .touchUpInside) 45 | button5.tag = 4 46 | 47 | toggler2 = Toggler(default: 0, togglers: [button6, button7, button8, button9, button10]) 48 | button6.addTarget(self, action: #selector(buttonClicked2(_:)), for: .touchUpInside) 49 | button7.addTarget(self, action: #selector(buttonClicked2(_:)), for: .touchUpInside) 50 | button8.addTarget(self, action: #selector(buttonClicked2(_:)), for: .touchUpInside) 51 | button9.addTarget(self, action: #selector(buttonClicked2(_:)), for: .touchUpInside) 52 | button10.addTarget(self, action: #selector(buttonClicked2(_:)), for: .touchUpInside) 53 | } 54 | 55 | func buttonClicked(_ sender: UIButton) { 56 | toggler.onAt(index: sender.tag) 57 | } 58 | 59 | func buttonClicked2(_ sender: UIButton) { 60 | toggler2.on(toggle: sender) 61 | } 62 | 63 | override func didReceiveMemoryWarning() { 64 | super.didReceiveMemoryWarning() 65 | } 66 | 67 | 68 | } 69 | 70 | --------------------------------------------------------------------------------