├── .gitignore ├── Inspector.gif ├── LICENSE ├── MenuButton.xcodeproj └── project.pbxproj ├── MenuButton ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── MenuButton.swift └── ViewController.swift ├── Preview.gif └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | # Pods/ 27 | 28 | # Carthage 29 | # 30 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 31 | # Carthage/Checkouts 32 | 33 | Carthage/Build 34 | -------------------------------------------------------------------------------- /Inspector.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/toannt/Hamburger-Menu-Button/11d199cddc52acb2744592ecc057fa5066f2eea0/Inspector.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 toannt 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 | 23 | -------------------------------------------------------------------------------- /MenuButton.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | E8F2C6CF1BE0C8B70003DD72 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8F2C6CE1BE0C8B70003DD72 /* AppDelegate.swift */; }; 11 | E8F2C6D11BE0C8B70003DD72 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8F2C6D01BE0C8B70003DD72 /* ViewController.swift */; }; 12 | E8F2C6D41BE0C8B70003DD72 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E8F2C6D21BE0C8B70003DD72 /* Main.storyboard */; }; 13 | E8F2C6D61BE0C8B70003DD72 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E8F2C6D51BE0C8B70003DD72 /* Assets.xcassets */; }; 14 | E8F2C6D91BE0C8B70003DD72 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E8F2C6D71BE0C8B70003DD72 /* LaunchScreen.storyboard */; }; 15 | E8F2C6E11BE0C8D00003DD72 /* MenuButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8F2C6E01BE0C8D00003DD72 /* MenuButton.swift */; settings = {ASSET_TAGS = (); }; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | E8F2C6CB1BE0C8B70003DD72 /* MenuButton.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MenuButton.app; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | E8F2C6CE1BE0C8B70003DD72 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 21 | E8F2C6D01BE0C8B70003DD72 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 22 | E8F2C6D31BE0C8B70003DD72 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 23 | E8F2C6D51BE0C8B70003DD72 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 24 | E8F2C6D81BE0C8B70003DD72 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 25 | E8F2C6DA1BE0C8B70003DD72 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 26 | E8F2C6E01BE0C8D00003DD72 /* MenuButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuButton.swift; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | E8F2C6C81BE0C8B70003DD72 /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXFrameworksBuildPhase section */ 38 | 39 | /* Begin PBXGroup section */ 40 | E8F2C6C21BE0C8B70003DD72 = { 41 | isa = PBXGroup; 42 | children = ( 43 | E8F2C6CD1BE0C8B70003DD72 /* MenuButton */, 44 | E8F2C6CC1BE0C8B70003DD72 /* Products */, 45 | ); 46 | sourceTree = ""; 47 | }; 48 | E8F2C6CC1BE0C8B70003DD72 /* Products */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | E8F2C6CB1BE0C8B70003DD72 /* MenuButton.app */, 52 | ); 53 | name = Products; 54 | sourceTree = ""; 55 | }; 56 | E8F2C6CD1BE0C8B70003DD72 /* MenuButton */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | E8F2C6CE1BE0C8B70003DD72 /* AppDelegate.swift */, 60 | E8F2C6D01BE0C8B70003DD72 /* ViewController.swift */, 61 | E8F2C6E01BE0C8D00003DD72 /* MenuButton.swift */, 62 | E8F2C6D21BE0C8B70003DD72 /* Main.storyboard */, 63 | E8F2C6D51BE0C8B70003DD72 /* Assets.xcassets */, 64 | E8F2C6D71BE0C8B70003DD72 /* LaunchScreen.storyboard */, 65 | E8F2C6DA1BE0C8B70003DD72 /* Info.plist */, 66 | ); 67 | path = MenuButton; 68 | sourceTree = ""; 69 | }; 70 | /* End PBXGroup section */ 71 | 72 | /* Begin PBXNativeTarget section */ 73 | E8F2C6CA1BE0C8B70003DD72 /* MenuButton */ = { 74 | isa = PBXNativeTarget; 75 | buildConfigurationList = E8F2C6DD1BE0C8B70003DD72 /* Build configuration list for PBXNativeTarget "MenuButton" */; 76 | buildPhases = ( 77 | E8F2C6C71BE0C8B70003DD72 /* Sources */, 78 | E8F2C6C81BE0C8B70003DD72 /* Frameworks */, 79 | E8F2C6C91BE0C8B70003DD72 /* Resources */, 80 | ); 81 | buildRules = ( 82 | ); 83 | dependencies = ( 84 | ); 85 | name = MenuButton; 86 | productName = MenuButton; 87 | productReference = E8F2C6CB1BE0C8B70003DD72 /* MenuButton.app */; 88 | productType = "com.apple.product-type.application"; 89 | }; 90 | /* End PBXNativeTarget section */ 91 | 92 | /* Begin PBXProject section */ 93 | E8F2C6C31BE0C8B70003DD72 /* Project object */ = { 94 | isa = PBXProject; 95 | attributes = { 96 | LastUpgradeCheck = 0700; 97 | ORGANIZATIONNAME = "Toan Nguyen"; 98 | TargetAttributes = { 99 | E8F2C6CA1BE0C8B70003DD72 = { 100 | CreatedOnToolsVersion = 7.0.1; 101 | }; 102 | }; 103 | }; 104 | buildConfigurationList = E8F2C6C61BE0C8B70003DD72 /* Build configuration list for PBXProject "MenuButton" */; 105 | compatibilityVersion = "Xcode 3.2"; 106 | developmentRegion = English; 107 | hasScannedForEncodings = 0; 108 | knownRegions = ( 109 | en, 110 | Base, 111 | ); 112 | mainGroup = E8F2C6C21BE0C8B70003DD72; 113 | productRefGroup = E8F2C6CC1BE0C8B70003DD72 /* Products */; 114 | projectDirPath = ""; 115 | projectRoot = ""; 116 | targets = ( 117 | E8F2C6CA1BE0C8B70003DD72 /* MenuButton */, 118 | ); 119 | }; 120 | /* End PBXProject section */ 121 | 122 | /* Begin PBXResourcesBuildPhase section */ 123 | E8F2C6C91BE0C8B70003DD72 /* Resources */ = { 124 | isa = PBXResourcesBuildPhase; 125 | buildActionMask = 2147483647; 126 | files = ( 127 | E8F2C6D91BE0C8B70003DD72 /* LaunchScreen.storyboard in Resources */, 128 | E8F2C6D61BE0C8B70003DD72 /* Assets.xcassets in Resources */, 129 | E8F2C6D41BE0C8B70003DD72 /* Main.storyboard in Resources */, 130 | ); 131 | runOnlyForDeploymentPostprocessing = 0; 132 | }; 133 | /* End PBXResourcesBuildPhase section */ 134 | 135 | /* Begin PBXSourcesBuildPhase section */ 136 | E8F2C6C71BE0C8B70003DD72 /* Sources */ = { 137 | isa = PBXSourcesBuildPhase; 138 | buildActionMask = 2147483647; 139 | files = ( 140 | E8F2C6D11BE0C8B70003DD72 /* ViewController.swift in Sources */, 141 | E8F2C6CF1BE0C8B70003DD72 /* AppDelegate.swift in Sources */, 142 | E8F2C6E11BE0C8D00003DD72 /* MenuButton.swift in Sources */, 143 | ); 144 | runOnlyForDeploymentPostprocessing = 0; 145 | }; 146 | /* End PBXSourcesBuildPhase section */ 147 | 148 | /* Begin PBXVariantGroup section */ 149 | E8F2C6D21BE0C8B70003DD72 /* Main.storyboard */ = { 150 | isa = PBXVariantGroup; 151 | children = ( 152 | E8F2C6D31BE0C8B70003DD72 /* Base */, 153 | ); 154 | name = Main.storyboard; 155 | sourceTree = ""; 156 | }; 157 | E8F2C6D71BE0C8B70003DD72 /* LaunchScreen.storyboard */ = { 158 | isa = PBXVariantGroup; 159 | children = ( 160 | E8F2C6D81BE0C8B70003DD72 /* Base */, 161 | ); 162 | name = LaunchScreen.storyboard; 163 | sourceTree = ""; 164 | }; 165 | /* End PBXVariantGroup section */ 166 | 167 | /* Begin XCBuildConfiguration section */ 168 | E8F2C6DB1BE0C8B70003DD72 /* Debug */ = { 169 | isa = XCBuildConfiguration; 170 | buildSettings = { 171 | ALWAYS_SEARCH_USER_PATHS = NO; 172 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 173 | CLANG_CXX_LIBRARY = "libc++"; 174 | CLANG_ENABLE_MODULES = YES; 175 | CLANG_ENABLE_OBJC_ARC = YES; 176 | CLANG_WARN_BOOL_CONVERSION = YES; 177 | CLANG_WARN_CONSTANT_CONVERSION = YES; 178 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 179 | CLANG_WARN_EMPTY_BODY = YES; 180 | CLANG_WARN_ENUM_CONVERSION = YES; 181 | CLANG_WARN_INT_CONVERSION = YES; 182 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 183 | CLANG_WARN_UNREACHABLE_CODE = YES; 184 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 185 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 186 | COPY_PHASE_STRIP = NO; 187 | DEBUG_INFORMATION_FORMAT = dwarf; 188 | ENABLE_STRICT_OBJC_MSGSEND = YES; 189 | ENABLE_TESTABILITY = YES; 190 | GCC_C_LANGUAGE_STANDARD = gnu99; 191 | GCC_DYNAMIC_NO_PIC = NO; 192 | GCC_NO_COMMON_BLOCKS = YES; 193 | GCC_OPTIMIZATION_LEVEL = 0; 194 | GCC_PREPROCESSOR_DEFINITIONS = ( 195 | "DEBUG=1", 196 | "$(inherited)", 197 | ); 198 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 199 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 200 | GCC_WARN_UNDECLARED_SELECTOR = YES; 201 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 202 | GCC_WARN_UNUSED_FUNCTION = YES; 203 | GCC_WARN_UNUSED_VARIABLE = YES; 204 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 205 | MTL_ENABLE_DEBUG_INFO = YES; 206 | ONLY_ACTIVE_ARCH = YES; 207 | SDKROOT = iphoneos; 208 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 209 | TARGETED_DEVICE_FAMILY = "1,2"; 210 | }; 211 | name = Debug; 212 | }; 213 | E8F2C6DC1BE0C8B70003DD72 /* Release */ = { 214 | isa = XCBuildConfiguration; 215 | buildSettings = { 216 | ALWAYS_SEARCH_USER_PATHS = NO; 217 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 218 | CLANG_CXX_LIBRARY = "libc++"; 219 | CLANG_ENABLE_MODULES = YES; 220 | CLANG_ENABLE_OBJC_ARC = YES; 221 | CLANG_WARN_BOOL_CONVERSION = YES; 222 | CLANG_WARN_CONSTANT_CONVERSION = YES; 223 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 224 | CLANG_WARN_EMPTY_BODY = YES; 225 | CLANG_WARN_ENUM_CONVERSION = YES; 226 | CLANG_WARN_INT_CONVERSION = YES; 227 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 228 | CLANG_WARN_UNREACHABLE_CODE = YES; 229 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 230 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 231 | COPY_PHASE_STRIP = NO; 232 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 233 | ENABLE_NS_ASSERTIONS = NO; 234 | ENABLE_STRICT_OBJC_MSGSEND = YES; 235 | GCC_C_LANGUAGE_STANDARD = gnu99; 236 | GCC_NO_COMMON_BLOCKS = YES; 237 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 238 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 239 | GCC_WARN_UNDECLARED_SELECTOR = YES; 240 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 241 | GCC_WARN_UNUSED_FUNCTION = YES; 242 | GCC_WARN_UNUSED_VARIABLE = YES; 243 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 244 | MTL_ENABLE_DEBUG_INFO = NO; 245 | SDKROOT = iphoneos; 246 | TARGETED_DEVICE_FAMILY = "1,2"; 247 | VALIDATE_PRODUCT = YES; 248 | }; 249 | name = Release; 250 | }; 251 | E8F2C6DE1BE0C8B70003DD72 /* Debug */ = { 252 | isa = XCBuildConfiguration; 253 | buildSettings = { 254 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 255 | INFOPLIST_FILE = MenuButton/Info.plist; 256 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 257 | PRODUCT_BUNDLE_IDENTIFIER = com.waterstudio.MenuButton; 258 | PRODUCT_NAME = "$(TARGET_NAME)"; 259 | }; 260 | name = Debug; 261 | }; 262 | E8F2C6DF1BE0C8B70003DD72 /* Release */ = { 263 | isa = XCBuildConfiguration; 264 | buildSettings = { 265 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 266 | INFOPLIST_FILE = MenuButton/Info.plist; 267 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 268 | PRODUCT_BUNDLE_IDENTIFIER = com.waterstudio.MenuButton; 269 | PRODUCT_NAME = "$(TARGET_NAME)"; 270 | }; 271 | name = Release; 272 | }; 273 | /* End XCBuildConfiguration section */ 274 | 275 | /* Begin XCConfigurationList section */ 276 | E8F2C6C61BE0C8B70003DD72 /* Build configuration list for PBXProject "MenuButton" */ = { 277 | isa = XCConfigurationList; 278 | buildConfigurations = ( 279 | E8F2C6DB1BE0C8B70003DD72 /* Debug */, 280 | E8F2C6DC1BE0C8B70003DD72 /* Release */, 281 | ); 282 | defaultConfigurationIsVisible = 0; 283 | defaultConfigurationName = Release; 284 | }; 285 | E8F2C6DD1BE0C8B70003DD72 /* Build configuration list for PBXNativeTarget "MenuButton" */ = { 286 | isa = XCConfigurationList; 287 | buildConfigurations = ( 288 | E8F2C6DE1BE0C8B70003DD72 /* Debug */, 289 | E8F2C6DF1BE0C8B70003DD72 /* Release */, 290 | ); 291 | defaultConfigurationIsVisible = 0; 292 | }; 293 | /* End XCConfigurationList section */ 294 | }; 295 | rootObject = E8F2C6C31BE0C8B70003DD72 /* Project object */; 296 | } 297 | -------------------------------------------------------------------------------- /MenuButton/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // MenuButton 4 | // 5 | // Created by Toan Nguyen on 10/28/15. 6 | // Copyright © 2015 Toan Nguyen. 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: [NSObject: AnyObject]?) -> 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 throttle down OpenGL ES frame rates. 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 inactive 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 | -------------------------------------------------------------------------------- /MenuButton/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /MenuButton/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 | 27 | 28 | -------------------------------------------------------------------------------- /MenuButton/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 39 | 51 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /MenuButton/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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /MenuButton/MenuButton.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MenuButton.swift 3 | // Draw 4 | // 5 | // Created by Toan Nguyen on 10/28/15. 6 | // Copyright © 2015 Toan Nguyen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import QuartzCore 11 | 12 | class MenuButton: UIButton { 13 | 14 | var menuPath : CGPath { 15 | let path = CGPathCreateMutable() 16 | CGPathMoveToPoint(path, nil, thickness / 2, thickness / 2) 17 | CGPathAddLineToPoint(path, nil, lineWidth - thickness / 2, thickness / 2) 18 | return path 19 | } 20 | 21 | var sidePath: CGPath { 22 | let path = CGPathCreateMutable() 23 | CGPathMoveToPoint(path, nil, 0, self.bounds.height / 2) 24 | CGPathAddLineToPoint(path, nil, self.bounds.width, self.bounds.height/2) 25 | return path 26 | } 27 | 28 | let animateDuration : Double = 0.3 29 | let animateDelay: Double = 0.05 30 | 31 | 32 | @IBInspectable var lineWidth : CGFloat = 28{ 33 | didSet{ 34 | self.updateSubLayers() 35 | } 36 | } 37 | 38 | @IBInspectable var thickness : CGFloat = 4{ 39 | didSet{ 40 | self.updateSubLayers() 41 | } 42 | } 43 | 44 | @IBInspectable var lineMargin : CGFloat = 10{ 45 | didSet{ 46 | self.updateSubLayers() 47 | } 48 | } 49 | 50 | @IBInspectable var lineCapRound : Bool = true{ 51 | didSet{ 52 | self.updateSubLayers() 53 | } 54 | } 55 | 56 | @IBInspectable var cornerRadius: CGFloat = 0{ 57 | didSet{ 58 | self.layer.cornerRadius = cornerRadius 59 | } 60 | } 61 | 62 | @IBInspectable var strokeColor : UIColor = UIColor.whiteColor(){ 63 | didSet{ 64 | self.updateSubLayers() 65 | } 66 | } 67 | 68 | @IBInspectable var slideLeftToRight : Bool = true { 69 | didSet{ 70 | if slideLeftToRight { 71 | sideLayer.strokeStart = 0.0 72 | sideLayer.strokeEnd = 0.0 73 | }else{ 74 | sideLayer.strokeStart = 1.0 75 | sideLayer.strokeEnd = 1.0 76 | } 77 | } 78 | } 79 | 80 | 81 | override var selected: Bool{ 82 | didSet{ 83 | self.showMenu(self.selected) 84 | } 85 | } 86 | 87 | 88 | 89 | let topLayer = CAShapeLayer() 90 | let midLayer = CAShapeLayer() 91 | let bottomLayer = CAShapeLayer() 92 | let sideLayer = CAShapeLayer() 93 | 94 | override init(frame: CGRect) { 95 | super.init(frame: frame) 96 | self.setups() 97 | } 98 | 99 | required init?(coder aDecoder: NSCoder) { 100 | super.init(coder: aDecoder) 101 | self.setups() 102 | } 103 | 104 | func setups(){ 105 | sideLayer.opacity = 0.2 106 | sideLayer.strokeColor = UIColor.blackColor().CGColor 107 | if slideLeftToRight { 108 | sideLayer.strokeStart = 0.0 109 | sideLayer.strokeEnd = 0.0 110 | }else{ 111 | sideLayer.strokeStart = 1.0 112 | sideLayer.strokeEnd = 1.0 113 | } 114 | for layer in [sideLayer, topLayer, midLayer, bottomLayer] { 115 | layer.masksToBounds = true 116 | layer.actions = [ 117 | "strokeStart": NSNull(), 118 | "strokeEnd": NSNull(), 119 | ] 120 | self.layer.addSublayer(layer) 121 | } 122 | self.layer.masksToBounds = true 123 | self.updateSubLayers() 124 | } 125 | 126 | func showMenu(isShow: Bool){ 127 | if isShow{ 128 | let sideAnim = CABasicAnimation(keyPath: slideLeftToRight ? "strokeEnd" : "strokeStart") 129 | sideAnim.duration = animateDuration - 0.1 130 | sideAnim.beginTime = CACurrentMediaTime() + 0.1 131 | sideAnim.toValue = slideLeftToRight ? 0.6 : 0.4 132 | sideAnim.fillMode = kCAFillModeBackwards 133 | sideLayer.applyAnimation(sideAnim) 134 | 135 | for (idx, layer) in [topLayer, midLayer, bottomLayer].enumerate(){ 136 | let anim = CABasicAnimation(keyPath: slideLeftToRight ? "strokeEnd" : "strokeStart") 137 | anim.toValue = slideLeftToRight ? 0.3 : 0.7 138 | anim.duration = animateDuration 139 | anim.fillMode = kCAFillModeBackwards 140 | anim.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) 141 | anim.beginTime = CACurrentMediaTime() + Double(idx) * animateDelay 142 | layer.applyAnimation(anim) 143 | } 144 | 145 | }else{ 146 | let sideAnim = CABasicAnimation(keyPath: slideLeftToRight ? "strokeEnd" : "strokeStart") 147 | sideAnim.duration = animateDuration - 0.1 148 | sideAnim.beginTime = CACurrentMediaTime() + 0.1 149 | sideAnim.toValue = slideLeftToRight ? 0.0 : 1.0 150 | sideAnim.fillMode = kCAFillModeBackwards 151 | sideLayer.applyAnimation(sideAnim) 152 | 153 | for (idx, layer) in [topLayer, midLayer, bottomLayer].enumerate(){ 154 | let anim = CABasicAnimation(keyPath: slideLeftToRight ? "strokeEnd" : "strokeStart") 155 | anim.toValue = slideLeftToRight ? 1.0 : 0.0 156 | anim.duration = animateDuration 157 | anim.fillMode = kCAFillModeBackwards 158 | anim.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) 159 | anim.beginTime = CACurrentMediaTime() + Double(idx) * animateDelay 160 | layer.applyAnimation(anim) 161 | } 162 | } 163 | } 164 | 165 | 166 | func updateSubLayers(){ 167 | let path = self.menuPath 168 | let strokingPath = CGPathCreateCopyByStrokingPath(path, nil, thickness, CGLineCap.Round, CGLineJoin.Miter, 10) 169 | let bounds = CGPathGetPathBoundingBox(strokingPath) 170 | for layer in [topLayer, midLayer, bottomLayer] { 171 | layer.path = path 172 | layer.bounds = bounds 173 | layer.strokeColor = self.strokeColor.CGColor 174 | layer.lineWidth = thickness 175 | layer.lineCap = lineCapRound ? kCALineCapRound : kCALineCapSquare 176 | } 177 | self.setNeedsLayout() 178 | } 179 | 180 | 181 | override func layoutSubviews() { 182 | let center = CGPoint(x: self.bounds.size.width/2, y: self.bounds.size.height/2) 183 | self.midLayer.position = center 184 | self.topLayer.position = CGPoint(x: center.x, y: center.y - lineMargin) 185 | self.bottomLayer.position = CGPoint(x: center.x, y: center.y + lineMargin) 186 | sideLayer.bounds = self.bounds 187 | sideLayer.path = sidePath 188 | sideLayer.lineWidth = self.bounds.height 189 | sideLayer.position = center 190 | } 191 | } 192 | 193 | extension CALayer { 194 | func applyAnimation(animation: CABasicAnimation) { 195 | let copy = animation.copy() as! CABasicAnimation 196 | if copy.fromValue == nil { 197 | copy.fromValue = self.presentationLayer()!.valueForKeyPath(copy.keyPath!) 198 | } 199 | self.addAnimation(copy, forKey: copy.keyPath) 200 | self.setValue(copy.toValue, forKeyPath:copy.keyPath!) 201 | } 202 | } 203 | 204 | -------------------------------------------------------------------------------- /MenuButton/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // MenuButton 4 | // 5 | // Created by Toan Nguyen on 10/28/15. 6 | // Copyright © 2015 Toan Nguyen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import QuartzCore 11 | class ViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | let firstButton = MenuButton(frame: CGRectMake(0, 0, 60, 60)) 16 | firstButton.center = CGPoint(x: self.view.bounds.width/2, y: 350) 17 | firstButton.addTarget(self, action: "buttonClick:", forControlEvents: UIControlEvents.TouchUpInside) 18 | firstButton.lineWidth = 30 19 | firstButton.lineMargin = 12 20 | firstButton.lineCapRound = true 21 | firstButton.thickness = 6 22 | firstButton.slideLeftToRight = false 23 | firstButton.backgroundColor = UIColor.purpleColor() 24 | firstButton.cornerRadius = 10 25 | self.view.addSubview(firstButton) 26 | 27 | let secondButton = MenuButton(frame: CGRectMake(0, 0, 60, 60)) 28 | secondButton.center = CGPoint(x: self.view.bounds.width/2, y: 420) 29 | secondButton.addTarget(self, action: "buttonClick:", forControlEvents: UIControlEvents.TouchUpInside) 30 | secondButton.lineWidth = 30 31 | secondButton.lineMargin = 12 32 | secondButton.lineCapRound = true 33 | secondButton.thickness = 6 34 | secondButton.slideLeftToRight = false 35 | secondButton.backgroundColor = UIColor.clearColor() 36 | secondButton.layer.borderWidth = 2.0 37 | secondButton.layer.borderColor = UIColor.orangeColor().CGColor 38 | secondButton.cornerRadius = secondButton.bounds.width/2 39 | secondButton.strokeColor = UIColor.blueColor() 40 | self.view.addSubview(secondButton) 41 | // Do any additional setup after loading the view, typically from a nib. 42 | } 43 | 44 | 45 | @IBAction func buttonClick(sender: UIButton) { 46 | sender.selected = !sender.selected 47 | } 48 | 49 | } 50 | 51 | -------------------------------------------------------------------------------- /Preview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/toannt/Hamburger-Menu-Button/11d199cddc52acb2744592ecc057fa5066f2eea0/Preview.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hamburger Menu Button 2 | A hamburger menu button with full customization. Inspired by [VinhLe's idea on the Dribble](https://dribbble.com/shots/1626236-Dribbble-Menu) 3 | 4 | ![Preview](./Preview.gif) 5 | 6 | # How to use it 7 | You can config the looks of the button through Xcode Inspector 8 | 9 | ![Xcode Inspector](./Inspector.gif) 10 | 11 | Or you can make a button on your own by doing this: 12 | ``` 13 | let firstButton = MenuButton(frame: CGRectMake(100, 100, 60, 60)) 14 | firstButton.addTarget(self, action: "buttonClick:", forControlEvents: UIControlEvents.TouchUpInside) 15 | firstButton.lineWidth = 30 16 | firstButton.lineMargin = 12 17 | firstButton.lineCapRound = true 18 | firstButton.thickness = 6 19 | firstButton.slideLeftToRight = false 20 | firstButton.backgroundColor = UIColor.purpleColor() 21 | firstButton.cornerRadius = 10 22 | self.view.addSubview(firstButton) 23 | ``` 24 | # License 25 | MIT license. See the `LICENSE` file for details. 26 | --------------------------------------------------------------------------------