├── LICENSE
├── README.md
├── SHToggleButton.xcodeproj
├── project.pbxproj
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ │ └── IDEWorkspaceChecks.plist
└── xcuserdata
│ └── tr.xcuserdatad
│ └── xcschemes
│ └── xcschememanagement.plist
└── SHToggleButton
├── AppDelegate.swift
├── Assets.xcassets
├── AppIcon.appiconset
│ └── Contents.json
├── Contents.json
├── like-off.imageset
│ ├── Contents.json
│ └── like (1).png
└── like-on.imageset
│ ├── Contents.json
│ └── like (2).png
├── Base.lproj
├── LaunchScreen.storyboard
└── Main.storyboard
├── ButtonClicked.gif
├── Info.plist
├── SHToggleButton.swift
├── Settings.png
└── ViewController.swift
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Soufian Hossam
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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SHToggleButton
2 | A toggle button with a cool animaiton.
3 |
4 | ## Overview
5 |
6 |
7 |
8 | ## How to use
9 |
10 | 1- Drag a UIButton object and set it's custom class to SHToggleButton.
11 |
12 | 2- Make sure that you change button type to *Custom*
13 |
14 | 3- Select Default, Selected image and Image to animate.
15 |
16 |
17 |
18 |
19 | ## Installation
20 |
21 | Just include *SHToggleButton.swift* in your project.
22 |
23 | ## Demo
24 |
25 | Download and run the project.
26 |
27 | ## License
28 |
29 | This project is licensed under the MIT License - see the [LICENSE.md](LICENSE) file for details
30 |
31 |
32 |
--------------------------------------------------------------------------------
/SHToggleButton.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 48;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 3142D3A421525D60007670D7 /* ButtonClicked.gif in Resources */ = {isa = PBXBuildFile; fileRef = 3142D3A321525D5F007670D7 /* ButtonClicked.gif */; };
11 | 3142D3A6215261F6007670D7 /* Settings.png in Resources */ = {isa = PBXBuildFile; fileRef = 3142D3A5215261F6007670D7 /* Settings.png */; };
12 | 3161DCDA2151313300F9C010 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3161DCD92151313300F9C010 /* AppDelegate.swift */; };
13 | 3161DCDC2151313300F9C010 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3161DCDB2151313300F9C010 /* ViewController.swift */; };
14 | 3161DCDF2151313300F9C010 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3161DCDD2151313300F9C010 /* Main.storyboard */; };
15 | 3161DCE12151313300F9C010 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3161DCE02151313300F9C010 /* Assets.xcassets */; };
16 | 3161DCE42151313300F9C010 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3161DCE22151313300F9C010 /* LaunchScreen.storyboard */; };
17 | 3161DCEC2151314E00F9C010 /* SHToggleButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3161DCEB2151314E00F9C010 /* SHToggleButton.swift */; };
18 | /* End PBXBuildFile section */
19 |
20 | /* Begin PBXFileReference section */
21 | 3142D3A321525D5F007670D7 /* ButtonClicked.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = ButtonClicked.gif; sourceTree = ""; };
22 | 3142D3A5215261F6007670D7 /* Settings.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Settings.png; sourceTree = ""; };
23 | 3161DCD62151313300F9C010 /* SHToggleButton.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SHToggleButton.app; sourceTree = BUILT_PRODUCTS_DIR; };
24 | 3161DCD92151313300F9C010 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
25 | 3161DCDB2151313300F9C010 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; };
26 | 3161DCDE2151313300F9C010 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
27 | 3161DCE02151313300F9C010 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
28 | 3161DCE32151313300F9C010 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
29 | 3161DCE52151313300F9C010 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
30 | 3161DCEB2151314E00F9C010 /* SHToggleButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SHToggleButton.swift; sourceTree = ""; };
31 | /* End PBXFileReference section */
32 |
33 | /* Begin PBXFrameworksBuildPhase section */
34 | 3161DCD32151313300F9C010 /* Frameworks */ = {
35 | isa = PBXFrameworksBuildPhase;
36 | buildActionMask = 2147483647;
37 | files = (
38 | );
39 | runOnlyForDeploymentPostprocessing = 0;
40 | };
41 | /* End PBXFrameworksBuildPhase section */
42 |
43 | /* Begin PBXGroup section */
44 | 3161DCCD2151313300F9C010 = {
45 | isa = PBXGroup;
46 | children = (
47 | 3161DCD82151313300F9C010 /* SHToggleButton */,
48 | 3161DCD72151313300F9C010 /* Products */,
49 | );
50 | sourceTree = "";
51 | };
52 | 3161DCD72151313300F9C010 /* Products */ = {
53 | isa = PBXGroup;
54 | children = (
55 | 3161DCD62151313300F9C010 /* SHToggleButton.app */,
56 | );
57 | name = Products;
58 | sourceTree = "";
59 | };
60 | 3161DCD82151313300F9C010 /* SHToggleButton */ = {
61 | isa = PBXGroup;
62 | children = (
63 | 3142D3A321525D5F007670D7 /* ButtonClicked.gif */,
64 | 3142D3A5215261F6007670D7 /* Settings.png */,
65 | 3161DCD92151313300F9C010 /* AppDelegate.swift */,
66 | 3161DCDB2151313300F9C010 /* ViewController.swift */,
67 | 3161DCEB2151314E00F9C010 /* SHToggleButton.swift */,
68 | 3161DCDD2151313300F9C010 /* Main.storyboard */,
69 | 3161DCE02151313300F9C010 /* Assets.xcassets */,
70 | 3161DCE22151313300F9C010 /* LaunchScreen.storyboard */,
71 | 3161DCE52151313300F9C010 /* Info.plist */,
72 | );
73 | path = SHToggleButton;
74 | sourceTree = "";
75 | };
76 | /* End PBXGroup section */
77 |
78 | /* Begin PBXNativeTarget section */
79 | 3161DCD52151313300F9C010 /* SHToggleButton */ = {
80 | isa = PBXNativeTarget;
81 | buildConfigurationList = 3161DCE82151313300F9C010 /* Build configuration list for PBXNativeTarget "SHToggleButton" */;
82 | buildPhases = (
83 | 3161DCD22151313300F9C010 /* Sources */,
84 | 3161DCD32151313300F9C010 /* Frameworks */,
85 | 3161DCD42151313300F9C010 /* Resources */,
86 | );
87 | buildRules = (
88 | );
89 | dependencies = (
90 | );
91 | name = SHToggleButton;
92 | productName = SHToggleButton;
93 | productReference = 3161DCD62151313300F9C010 /* SHToggleButton.app */;
94 | productType = "com.apple.product-type.application";
95 | };
96 | /* End PBXNativeTarget section */
97 |
98 | /* Begin PBXProject section */
99 | 3161DCCE2151313300F9C010 /* Project object */ = {
100 | isa = PBXProject;
101 | attributes = {
102 | LastSwiftUpdateCheck = 0920;
103 | LastUpgradeCheck = 0920;
104 | ORGANIZATIONNAME = "Soufian Hossam";
105 | TargetAttributes = {
106 | 3161DCD52151313300F9C010 = {
107 | CreatedOnToolsVersion = 9.2;
108 | ProvisioningStyle = Automatic;
109 | };
110 | };
111 | };
112 | buildConfigurationList = 3161DCD12151313300F9C010 /* Build configuration list for PBXProject "SHToggleButton" */;
113 | compatibilityVersion = "Xcode 8.0";
114 | developmentRegion = en;
115 | hasScannedForEncodings = 0;
116 | knownRegions = (
117 | en,
118 | Base,
119 | );
120 | mainGroup = 3161DCCD2151313300F9C010;
121 | productRefGroup = 3161DCD72151313300F9C010 /* Products */;
122 | projectDirPath = "";
123 | projectRoot = "";
124 | targets = (
125 | 3161DCD52151313300F9C010 /* SHToggleButton */,
126 | );
127 | };
128 | /* End PBXProject section */
129 |
130 | /* Begin PBXResourcesBuildPhase section */
131 | 3161DCD42151313300F9C010 /* Resources */ = {
132 | isa = PBXResourcesBuildPhase;
133 | buildActionMask = 2147483647;
134 | files = (
135 | 3142D3A6215261F6007670D7 /* Settings.png in Resources */,
136 | 3142D3A421525D60007670D7 /* ButtonClicked.gif in Resources */,
137 | 3161DCE42151313300F9C010 /* LaunchScreen.storyboard in Resources */,
138 | 3161DCE12151313300F9C010 /* Assets.xcassets in Resources */,
139 | 3161DCDF2151313300F9C010 /* Main.storyboard in Resources */,
140 | );
141 | runOnlyForDeploymentPostprocessing = 0;
142 | };
143 | /* End PBXResourcesBuildPhase section */
144 |
145 | /* Begin PBXSourcesBuildPhase section */
146 | 3161DCD22151313300F9C010 /* Sources */ = {
147 | isa = PBXSourcesBuildPhase;
148 | buildActionMask = 2147483647;
149 | files = (
150 | 3161DCEC2151314E00F9C010 /* SHToggleButton.swift in Sources */,
151 | 3161DCDC2151313300F9C010 /* ViewController.swift in Sources */,
152 | 3161DCDA2151313300F9C010 /* AppDelegate.swift in Sources */,
153 | );
154 | runOnlyForDeploymentPostprocessing = 0;
155 | };
156 | /* End PBXSourcesBuildPhase section */
157 |
158 | /* Begin PBXVariantGroup section */
159 | 3161DCDD2151313300F9C010 /* Main.storyboard */ = {
160 | isa = PBXVariantGroup;
161 | children = (
162 | 3161DCDE2151313300F9C010 /* Base */,
163 | );
164 | name = Main.storyboard;
165 | sourceTree = "";
166 | };
167 | 3161DCE22151313300F9C010 /* LaunchScreen.storyboard */ = {
168 | isa = PBXVariantGroup;
169 | children = (
170 | 3161DCE32151313300F9C010 /* Base */,
171 | );
172 | name = LaunchScreen.storyboard;
173 | sourceTree = "";
174 | };
175 | /* End PBXVariantGroup section */
176 |
177 | /* Begin XCBuildConfiguration section */
178 | 3161DCE62151313300F9C010 /* Debug */ = {
179 | isa = XCBuildConfiguration;
180 | buildSettings = {
181 | ALWAYS_SEARCH_USER_PATHS = NO;
182 | CLANG_ANALYZER_NONNULL = YES;
183 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
184 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
185 | CLANG_CXX_LIBRARY = "libc++";
186 | CLANG_ENABLE_MODULES = YES;
187 | CLANG_ENABLE_OBJC_ARC = YES;
188 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
189 | CLANG_WARN_BOOL_CONVERSION = YES;
190 | CLANG_WARN_COMMA = YES;
191 | CLANG_WARN_CONSTANT_CONVERSION = YES;
192 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
193 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
194 | CLANG_WARN_EMPTY_BODY = YES;
195 | CLANG_WARN_ENUM_CONVERSION = YES;
196 | CLANG_WARN_INFINITE_RECURSION = YES;
197 | CLANG_WARN_INT_CONVERSION = YES;
198 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
199 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
200 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
201 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
202 | CLANG_WARN_STRICT_PROTOTYPES = YES;
203 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
204 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
205 | CLANG_WARN_UNREACHABLE_CODE = YES;
206 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
207 | CODE_SIGN_IDENTITY = "iPhone Developer";
208 | COPY_PHASE_STRIP = NO;
209 | DEBUG_INFORMATION_FORMAT = dwarf;
210 | ENABLE_STRICT_OBJC_MSGSEND = YES;
211 | ENABLE_TESTABILITY = YES;
212 | GCC_C_LANGUAGE_STANDARD = gnu11;
213 | GCC_DYNAMIC_NO_PIC = NO;
214 | GCC_NO_COMMON_BLOCKS = YES;
215 | GCC_OPTIMIZATION_LEVEL = 0;
216 | GCC_PREPROCESSOR_DEFINITIONS = (
217 | "DEBUG=1",
218 | "$(inherited)",
219 | );
220 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
221 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
222 | GCC_WARN_UNDECLARED_SELECTOR = YES;
223 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
224 | GCC_WARN_UNUSED_FUNCTION = YES;
225 | GCC_WARN_UNUSED_VARIABLE = YES;
226 | IPHONEOS_DEPLOYMENT_TARGET = 11.2;
227 | MTL_ENABLE_DEBUG_INFO = YES;
228 | ONLY_ACTIVE_ARCH = YES;
229 | SDKROOT = iphoneos;
230 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
231 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
232 | };
233 | name = Debug;
234 | };
235 | 3161DCE72151313300F9C010 /* Release */ = {
236 | isa = XCBuildConfiguration;
237 | buildSettings = {
238 | ALWAYS_SEARCH_USER_PATHS = NO;
239 | CLANG_ANALYZER_NONNULL = YES;
240 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
241 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
242 | CLANG_CXX_LIBRARY = "libc++";
243 | CLANG_ENABLE_MODULES = YES;
244 | CLANG_ENABLE_OBJC_ARC = YES;
245 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
246 | CLANG_WARN_BOOL_CONVERSION = YES;
247 | CLANG_WARN_COMMA = YES;
248 | CLANG_WARN_CONSTANT_CONVERSION = YES;
249 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
250 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
251 | CLANG_WARN_EMPTY_BODY = YES;
252 | CLANG_WARN_ENUM_CONVERSION = YES;
253 | CLANG_WARN_INFINITE_RECURSION = YES;
254 | CLANG_WARN_INT_CONVERSION = YES;
255 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
256 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
257 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
258 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
259 | CLANG_WARN_STRICT_PROTOTYPES = YES;
260 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
261 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
262 | CLANG_WARN_UNREACHABLE_CODE = YES;
263 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
264 | CODE_SIGN_IDENTITY = "iPhone Developer";
265 | COPY_PHASE_STRIP = NO;
266 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
267 | ENABLE_NS_ASSERTIONS = NO;
268 | ENABLE_STRICT_OBJC_MSGSEND = YES;
269 | GCC_C_LANGUAGE_STANDARD = gnu11;
270 | GCC_NO_COMMON_BLOCKS = YES;
271 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
272 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
273 | GCC_WARN_UNDECLARED_SELECTOR = YES;
274 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
275 | GCC_WARN_UNUSED_FUNCTION = YES;
276 | GCC_WARN_UNUSED_VARIABLE = YES;
277 | IPHONEOS_DEPLOYMENT_TARGET = 11.2;
278 | MTL_ENABLE_DEBUG_INFO = NO;
279 | SDKROOT = iphoneos;
280 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
281 | VALIDATE_PRODUCT = YES;
282 | };
283 | name = Release;
284 | };
285 | 3161DCE92151313300F9C010 /* Debug */ = {
286 | isa = XCBuildConfiguration;
287 | buildSettings = {
288 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
289 | CODE_SIGN_STYLE = Automatic;
290 | DEVELOPMENT_TEAM = 86MGZ7B3XL;
291 | INFOPLIST_FILE = SHToggleButton/Info.plist;
292 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
293 | PRODUCT_BUNDLE_IDENTIFIER = com.SoufianHossam.SHToggleButton0;
294 | PRODUCT_NAME = "$(TARGET_NAME)";
295 | SWIFT_VERSION = 4.2;
296 | TARGETED_DEVICE_FAMILY = "1,2";
297 | };
298 | name = Debug;
299 | };
300 | 3161DCEA2151313300F9C010 /* Release */ = {
301 | isa = XCBuildConfiguration;
302 | buildSettings = {
303 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
304 | CODE_SIGN_STYLE = Automatic;
305 | DEVELOPMENT_TEAM = 86MGZ7B3XL;
306 | INFOPLIST_FILE = SHToggleButton/Info.plist;
307 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
308 | PRODUCT_BUNDLE_IDENTIFIER = com.SoufianHossam.SHToggleButton0;
309 | PRODUCT_NAME = "$(TARGET_NAME)";
310 | SWIFT_VERSION = 4.2;
311 | TARGETED_DEVICE_FAMILY = "1,2";
312 | };
313 | name = Release;
314 | };
315 | /* End XCBuildConfiguration section */
316 |
317 | /* Begin XCConfigurationList section */
318 | 3161DCD12151313300F9C010 /* Build configuration list for PBXProject "SHToggleButton" */ = {
319 | isa = XCConfigurationList;
320 | buildConfigurations = (
321 | 3161DCE62151313300F9C010 /* Debug */,
322 | 3161DCE72151313300F9C010 /* Release */,
323 | );
324 | defaultConfigurationIsVisible = 0;
325 | defaultConfigurationName = Release;
326 | };
327 | 3161DCE82151313300F9C010 /* Build configuration list for PBXNativeTarget "SHToggleButton" */ = {
328 | isa = XCConfigurationList;
329 | buildConfigurations = (
330 | 3161DCE92151313300F9C010 /* Debug */,
331 | 3161DCEA2151313300F9C010 /* Release */,
332 | );
333 | defaultConfigurationIsVisible = 0;
334 | defaultConfigurationName = Release;
335 | };
336 | /* End XCConfigurationList section */
337 | };
338 | rootObject = 3161DCCE2151313300F9C010 /* Project object */;
339 | }
340 |
--------------------------------------------------------------------------------
/SHToggleButton.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/SHToggleButton.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/SHToggleButton.xcodeproj/xcuserdata/tr.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | SHToggleButton.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 | SHToggleButton.xcscheme_^#shared#^_
13 |
14 | orderHint
15 | 0
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/SHToggleButton/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // SHToggleButton
4 | //
5 | // Created by Soufian Hossam on 9/18/18.
6 | // Copyright © 2018 Soufian Hossam. 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: [UIApplication.LaunchOptionsKey: 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 |
--------------------------------------------------------------------------------
/SHToggleButton/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 | "idiom" : "ios-marketing",
90 | "size" : "1024x1024",
91 | "scale" : "1x"
92 | }
93 | ],
94 | "info" : {
95 | "version" : 1,
96 | "author" : "xcode"
97 | }
98 | }
--------------------------------------------------------------------------------
/SHToggleButton/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
--------------------------------------------------------------------------------
/SHToggleButton/Assets.xcassets/like-off.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "like (1).png",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/SHToggleButton/Assets.xcassets/like-off.imageset/like (1).png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SoufianHossam/SHToggleButton/86e490da4bbea3d5dc18512be70edb5d9b61e0c3/SHToggleButton/Assets.xcassets/like-off.imageset/like (1).png
--------------------------------------------------------------------------------
/SHToggleButton/Assets.xcassets/like-on.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "like (2).png",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/SHToggleButton/Assets.xcassets/like-on.imageset/like (2).png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SoufianHossam/SHToggleButton/86e490da4bbea3d5dc18512be70edb5d9b61e0c3/SHToggleButton/Assets.xcassets/like-on.imageset/like (2).png
--------------------------------------------------------------------------------
/SHToggleButton/Base.lproj/LaunchScreen.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 |
--------------------------------------------------------------------------------
/SHToggleButton/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 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/SHToggleButton/ButtonClicked.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SoufianHossam/SHToggleButton/86e490da4bbea3d5dc18512be70edb5d9b61e0c3/SHToggleButton/ButtonClicked.gif
--------------------------------------------------------------------------------
/SHToggleButton/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
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 |
--------------------------------------------------------------------------------
/SHToggleButton/SHToggleButton.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SHToggleButton.swift
3 | // SHToggleButton
4 | //
5 | // Created by Soufian Hossam on 9/18/18.
6 | // Copyright © 2018 Soufian Hossam. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | @IBDesignable
12 | class SHToggleButton: UIButton {
13 | // MARK: - Variables
14 | private var fallingImage: UIImage?
15 |
16 | // MARK: - IBInspectable
17 | @IBInspectable var defaultImage: UIImage? {
18 | didSet {
19 | setImage(defaultImage, for: .normal)
20 | }
21 | }
22 |
23 | @IBInspectable var selectedImage: UIImage? {
24 | didSet {
25 | setImage(selectedImage, for: .selected)
26 | }
27 | }
28 |
29 | @IBInspectable var imageToAnimate: UIImage? {
30 | didSet {
31 | fallingImage = imageToAnimate
32 | }
33 | }
34 |
35 | override init(frame: CGRect) {
36 | super.init(frame: frame)
37 | setup()
38 | }
39 |
40 | required init?(coder aDecoder: NSCoder) {
41 | super.init(coder: aDecoder)
42 | setup()
43 | }
44 |
45 | private func setup() {
46 | isSelected = false
47 | addTarget(self, action: #selector(tap), for: .touchUpInside)
48 | }
49 |
50 | @objc private func tap() {
51 | isSelected = !isSelected
52 |
53 | if isSelected {
54 | bounceAnimation()
55 | fallingAnimation()
56 | }
57 | }
58 |
59 | private func bounceAnimation() {
60 | DispatchQueue.main.async {
61 | UIView.animate(withDuration: 0, animations: {
62 | self.transform = CGAffineTransform.identity.scaledBy(x: 1.5, y: 1.5)
63 |
64 | }, completion: { _ in
65 | UIView.animate(withDuration: 0.8, delay: 0, usingSpringWithDamping: 0.4, initialSpringVelocity: 0, options: .allowUserInteraction, animations: {
66 | self.transform = CGAffineTransform.identity.scaledBy(x: 1, y: 1)
67 | })
68 | })
69 | }
70 | }
71 |
72 | private func fallingAnimation() {
73 | let x = frame.width / 2
74 | let y = frame.height / 2
75 |
76 | for _ in 0...3 {
77 | let duration = 0.5 + drand48() * 0.5
78 |
79 | let imageView = UIImageView(image: fallingImage)
80 | imageView.frame = CGRect(x: x, y: y, width: frame.width * 0.7, height: frame.height * 0.7)
81 |
82 | addSubview(imageView)
83 |
84 | let animation = CAKeyframeAnimation(keyPath: "position")
85 | animation.path = createFallingPath(center: CGPoint(x: x, y: y))
86 | animation.duration = duration
87 | animation.fillMode = CAMediaTimingFillMode.forwards
88 | animation.isRemovedOnCompletion = false
89 | animation.timingFunctions = [CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut)]
90 |
91 | imageView.layer.add(animation, forKey: nil)
92 |
93 | UIView.animate(withDuration: duration, animations: {
94 | imageView.alpha = 0
95 | }, completion: { success in
96 | imageView.removeFromSuperview()
97 | })
98 | }
99 | }
100 |
101 | private func createFallingPath(center: CGPoint) -> CGPath {
102 | let lowerValue = -50
103 | let upperValue = 50
104 | let random = Double(Int(arc4random_uniform(UInt32(upperValue - lowerValue + 1))) + lowerValue)
105 |
106 | let path = UIBezierPath()
107 | path.move(to: CGPoint(x: center.x, y: center.y))
108 |
109 | let y = center.y + 200
110 | let endPoint = CGPoint(x: center.x + CGFloat(random), y: y)
111 |
112 | let cp1 = CGPoint(x: Double(center.x) + random, y: Double(center.y) - 80)
113 | let cp2 = CGPoint(x: Double(center.x) + random, y: Double(center.y) - 80)
114 |
115 | path.addCurve(to: endPoint, controlPoint1: cp1, controlPoint2: cp2)
116 | path.stroke()
117 | path.lineWidth = 3
118 |
119 | return path.cgPath
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/SHToggleButton/Settings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SoufianHossam/SHToggleButton/86e490da4bbea3d5dc18512be70edb5d9b61e0c3/SHToggleButton/Settings.png
--------------------------------------------------------------------------------
/SHToggleButton/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // SHToggleButton
4 | //
5 | // Created by Soufian Hossam on 9/18/18.
6 | // Copyright © 2018 Soufian Hossam. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | class ViewController: UIViewController {
12 |
13 | override func viewDidLoad() {
14 | super.viewDidLoad()
15 | // Do any additional setup after loading the view, typically from a nib.
16 | }
17 |
18 | override func didReceiveMemoryWarning() {
19 | super.didReceiveMemoryWarning()
20 | // Dispose of any resources that can be recreated.
21 | }
22 |
23 |
24 | }
25 |
26 |
--------------------------------------------------------------------------------