diff --git a/Action Button.png b/Action Button.png new file mode 100644 index 0000000..34277bf Binary files /dev/null and b/Action Button.png differ diff --git a/ActionButton.podspec b/ActionButton.podspec new file mode 100644 index 0000000..a7302ff --- /dev/null +++ b/ActionButton.podspec @@ -0,0 +1,24 @@ +# +# Be sure to run `pod lib lint ActionButton.podspec' to ensure this is a +# valid spec and remove all comments before submitting the spec. +# +# Any lines starting with a # are optional, but encouraged +# +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html +# + +Pod::Spec.new do |s| + s.name = "ActionButton" + s.version = "0.1.3" + s.summary = "Action button is a Floating Action Button inspired from Google Inbox implemented in Swift" + s.homepage = "https://github.com/lourenco-marinho/ActionButton" + # s.screenshots = "www.example.com/screenshots_1", "www.example.com/screenshots_2" + s.license = 'MIT' + s.author = { "Lourenço Marinho" => "lourenco.pmarinho@gmail.com" } + s.source = { :git => "https://github.com/lourenco-marinho/ActionButton.git", :tag => s.version.to_s } + s.social_media_url = 'https://twitter.com/lopima' + + s.platform = :ios, '8.0' + s.requires_arc = true + s.source_files = 'Source/*.swift' +end diff --git a/Example/.DS_Store b/Example/.DS_Store new file mode 100644 index 0000000..2ba162a Binary files /dev/null and b/Example/.DS_Store differ diff --git a/Example/ActionButton.xcodeproj/project.pbxproj b/Example/ActionButton.xcodeproj/project.pbxproj new file mode 100644 index 0000000..a03e532 --- /dev/null +++ b/Example/ActionButton.xcodeproj/project.pbxproj @@ -0,0 +1,439 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; }; + 607FACD81AFB9204008FA782 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD71AFB9204008FA782 /* ViewController.swift */; }; + 607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 607FACD91AFB9204008FA782 /* Main.storyboard */; }; + 607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; }; + 607FACEC1AFB9204008FA782 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACEB1AFB9204008FA782 /* Tests.swift */; }; + A90AD8EA1B13CA4700DE2695 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = A90AD8E91B13CA4700DE2695 /* LaunchScreen.xib */; }; + A9E513A91B13CE0200604F6B /* ActionButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E513A71B13CE0200604F6B /* ActionButton.swift */; }; + A9E513AA1B13CE0200604F6B /* ActionButtonItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E513A81B13CE0200604F6B /* ActionButtonItem.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 607FACE61AFB9204008FA782 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 607FACC81AFB9204008FA782 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 607FACCF1AFB9204008FA782; + remoteInfo = ActionButton; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 607FACD01AFB9204008FA782 /* ActionButton_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ActionButton_Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 607FACD41AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 607FACD51AFB9204008FA782 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 607FACD71AFB9204008FA782 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 607FACDA1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 607FACDC1AFB9204008FA782 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; + 607FACE51AFB9204008FA782 /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 607FACEA1AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 607FACEB1AFB9204008FA782 /* Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests.swift; sourceTree = ""; }; + A90AD8E91B13CA4700DE2695 /* LaunchScreen.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = LaunchScreen.xib; sourceTree = ""; }; + A9E513A71B13CE0200604F6B /* ActionButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionButton.swift; sourceTree = ""; }; + A9E513A81B13CE0200604F6B /* ActionButtonItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionButtonItem.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 607FACCD1AFB9204008FA782 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 607FACE21AFB9204008FA782 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 607FACC71AFB9204008FA782 = { + isa = PBXGroup; + children = ( + A9E513A61B13CE0200604F6B /* Source */, + 607FACD21AFB9204008FA782 /* Example for ActionButton */, + 607FACE81AFB9204008FA782 /* Tests */, + 607FACD11AFB9204008FA782 /* Products */, + ); + sourceTree = ""; + }; + 607FACD11AFB9204008FA782 /* Products */ = { + isa = PBXGroup; + children = ( + 607FACD01AFB9204008FA782 /* ActionButton_Example.app */, + 607FACE51AFB9204008FA782 /* Tests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 607FACD21AFB9204008FA782 /* Example for ActionButton */ = { + isa = PBXGroup; + children = ( + 607FACDC1AFB9204008FA782 /* Images.xcassets */, + 607FACD51AFB9204008FA782 /* AppDelegate.swift */, + 607FACD71AFB9204008FA782 /* ViewController.swift */, + 607FACD91AFB9204008FA782 /* Main.storyboard */, + A90AD8E91B13CA4700DE2695 /* LaunchScreen.xib */, + 607FACD31AFB9204008FA782 /* Supporting Files */, + ); + name = "Example for ActionButton"; + path = ActionButton; + sourceTree = ""; + }; + 607FACD31AFB9204008FA782 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 607FACD41AFB9204008FA782 /* Info.plist */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 607FACE81AFB9204008FA782 /* Tests */ = { + isa = PBXGroup; + children = ( + 607FACEB1AFB9204008FA782 /* Tests.swift */, + 607FACE91AFB9204008FA782 /* Supporting Files */, + ); + path = Tests; + sourceTree = ""; + }; + 607FACE91AFB9204008FA782 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 607FACEA1AFB9204008FA782 /* Info.plist */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + A9E513A61B13CE0200604F6B /* Source */ = { + isa = PBXGroup; + children = ( + A9E513A71B13CE0200604F6B /* ActionButton.swift */, + A9E513A81B13CE0200604F6B /* ActionButtonItem.swift */, + ); + path = Source; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 607FACCF1AFB9204008FA782 /* ActionButton_Example */ = { + isa = PBXNativeTarget; + buildConfigurationList = 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "ActionButton_Example" */; + buildPhases = ( + 607FACCC1AFB9204008FA782 /* Sources */, + 607FACCD1AFB9204008FA782 /* Frameworks */, + 607FACCE1AFB9204008FA782 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = ActionButton_Example; + productName = ActionButton; + productReference = 607FACD01AFB9204008FA782 /* ActionButton_Example.app */; + productType = "com.apple.product-type.application"; + }; + 607FACE41AFB9204008FA782 /* Tests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 607FACF21AFB9204008FA782 /* Build configuration list for PBXNativeTarget "Tests" */; + buildPhases = ( + 607FACE11AFB9204008FA782 /* Sources */, + 607FACE21AFB9204008FA782 /* Frameworks */, + 607FACE31AFB9204008FA782 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 607FACE71AFB9204008FA782 /* PBXTargetDependency */, + ); + name = Tests; + productName = Tests; + productReference = 607FACE51AFB9204008FA782 /* Tests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 607FACC81AFB9204008FA782 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0630; + ORGANIZATIONNAME = CocoaPods; + TargetAttributes = { + 607FACCF1AFB9204008FA782 = { + CreatedOnToolsVersion = 6.3.1; + }; + 607FACE41AFB9204008FA782 = { + CreatedOnToolsVersion = 6.3.1; + TestTargetID = 607FACCF1AFB9204008FA782; + }; + }; + }; + buildConfigurationList = 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "ActionButton" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 607FACC71AFB9204008FA782; + productRefGroup = 607FACD11AFB9204008FA782 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 607FACCF1AFB9204008FA782 /* ActionButton_Example */, + 607FACE41AFB9204008FA782 /* Tests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 607FACCE1AFB9204008FA782 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */, + A90AD8EA1B13CA4700DE2695 /* LaunchScreen.xib in Resources */, + 607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 607FACE31AFB9204008FA782 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 607FACCC1AFB9204008FA782 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 607FACD81AFB9204008FA782 /* ViewController.swift in Sources */, + 607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */, + A9E513AA1B13CE0200604F6B /* ActionButtonItem.swift in Sources */, + A9E513A91B13CE0200604F6B /* ActionButton.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 607FACE11AFB9204008FA782 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 607FACEC1AFB9204008FA782 /* Tests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 607FACE71AFB9204008FA782 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 607FACCF1AFB9204008FA782 /* ActionButton_Example */; + targetProxy = 607FACE61AFB9204008FA782 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 607FACD91AFB9204008FA782 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 607FACDA1AFB9204008FA782 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 607FACED1AFB9204008FA782 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.3; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 607FACEE1AFB9204008FA782 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.3; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 607FACF01AFB9204008FA782 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + INFOPLIST_FILE = ActionButton/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + MODULE_NAME = ExampleApp; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 607FACF11AFB9204008FA782 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + INFOPLIST_FILE = ActionButton/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + MODULE_NAME = ExampleApp; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; + 607FACF31AFB9204008FA782 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + FRAMEWORK_SEARCH_PATHS = ( + "$(SDKROOT)/Developer/Library/Frameworks", + "$(inherited)", + ); + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + INFOPLIST_FILE = Tests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ActionButton_Example.app/ActionButton_Example"; + }; + name = Debug; + }; + 607FACF41AFB9204008FA782 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + FRAMEWORK_SEARCH_PATHS = ( + "$(SDKROOT)/Developer/Library/Frameworks", + "$(inherited)", + ); + INFOPLIST_FILE = Tests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ActionButton_Example.app/ActionButton_Example"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "ActionButton" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 607FACED1AFB9204008FA782 /* Debug */, + 607FACEE1AFB9204008FA782 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "ActionButton_Example" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 607FACF01AFB9204008FA782 /* Debug */, + 607FACF11AFB9204008FA782 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 607FACF21AFB9204008FA782 /* Build configuration list for PBXNativeTarget "Tests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 607FACF31AFB9204008FA782 /* Debug */, + 607FACF41AFB9204008FA782 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 607FACC81AFB9204008FA782 /* Project object */; +} diff --git a/Example/ActionButton.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Example/ActionButton.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..c2489f5 --- /dev/null +++ b/Example/ActionButton.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Example/ActionButton.xcodeproj/project.xcworkspace/xcshareddata/ActionButton.xccheckout b/Example/ActionButton.xcodeproj/project.xcworkspace/xcshareddata/ActionButton.xccheckout new file mode 100644 index 0000000..40fb5f4 --- /dev/null +++ b/Example/ActionButton.xcodeproj/project.xcworkspace/xcshareddata/ActionButton.xccheckout @@ -0,0 +1,41 @@ + + + + + IDESourceControlProjectFavoriteDictionaryKey + + IDESourceControlProjectIdentifier + 694891F3-450D-4D72-B6B8-68A3A8B56506 + IDESourceControlProjectName + ActionButton + IDESourceControlProjectOriginsDictionary + + 8CED2B6590B31C3A38E6715AFB8326A2BB47FA3A + github.com:lourenco-marinho/ActionButton.git + + IDESourceControlProjectPath + Example/ActionButton.xcodeproj + IDESourceControlProjectRelativeInstallPathDictionary + + 8CED2B6590B31C3A38E6715AFB8326A2BB47FA3A + ../../.. + + IDESourceControlProjectURL + github.com:lourenco-marinho/ActionButton.git + IDESourceControlProjectVersion + 111 + IDESourceControlProjectWCCIdentifier + 8CED2B6590B31C3A38E6715AFB8326A2BB47FA3A + IDESourceControlProjectWCConfigurations + + + IDESourceControlRepositoryExtensionIdentifierKey + public.vcs.git + IDESourceControlWCCIdentifierKey + 8CED2B6590B31C3A38E6715AFB8326A2BB47FA3A + IDESourceControlWCCName + ActionButton + + + + diff --git a/Example/ActionButton.xcodeproj/project.xcworkspace/xcuserdata/lourencomarinho.xcuserdatad/UserInterfaceState.xcuserstate b/Example/ActionButton.xcodeproj/project.xcworkspace/xcuserdata/lourencomarinho.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..98a7120 Binary files /dev/null and b/Example/ActionButton.xcodeproj/project.xcworkspace/xcuserdata/lourencomarinho.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Example/ActionButton.xcodeproj/xcshareddata/xcschemes/ActionButton-Example.xcscheme b/Example/ActionButton.xcodeproj/xcshareddata/xcschemes/ActionButton-Example.xcscheme new file mode 100644 index 0000000..3a92053 --- /dev/null +++ b/Example/ActionButton.xcodeproj/xcshareddata/xcschemes/ActionButton-Example.xcscheme @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example/ActionButton.xcodeproj/xcuserdata/lourencomarinho.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Example/ActionButton.xcodeproj/xcuserdata/lourencomarinho.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..fe2b454 --- /dev/null +++ b/Example/ActionButton.xcodeproj/xcuserdata/lourencomarinho.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,5 @@ + + + diff --git a/Example/ActionButton.xcodeproj/xcuserdata/lourencomarinho.xcuserdatad/xcschemes/xcschememanagement.plist b/Example/ActionButton.xcodeproj/xcuserdata/lourencomarinho.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..a1575db --- /dev/null +++ b/Example/ActionButton.xcodeproj/xcuserdata/lourencomarinho.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,19 @@ + + + + + SuppressBuildableAutocreation + + 607FACCF1AFB9204008FA782 + + primary + + + 607FACE41AFB9204008FA782 + + primary + + + + + diff --git a/Example/ActionButton/.DS_Store b/Example/ActionButton/.DS_Store new file mode 100644 index 0000000..cb7a06e Binary files /dev/null and b/Example/ActionButton/.DS_Store differ diff --git a/Example/ActionButton/AppDelegate.swift b/Example/ActionButton/AppDelegate.swift new file mode 100644 index 0000000..a809e66 --- /dev/null +++ b/Example/ActionButton/AppDelegate.swift @@ -0,0 +1,46 @@ +// +// AppDelegate.swift +// ActionButton +// +// Created by Lourenço Marinho on 05/25/2015. +// Copyright (c) 05/25/2015 Lourenço Marinho. All rights reserved. +// + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + var window: UIWindow? + + + func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + // Override point for customization after application launch. + return true + } + + func applicationWillResignActive(application: UIApplication) { + // 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. + // 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. + } + + func applicationDidEnterBackground(application: UIApplication) { + // 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. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. + } + + func applicationWillEnterForeground(application: UIApplication) { + // 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. + } + + func applicationDidBecomeActive(application: UIApplication) { + // 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. + } + + func applicationWillTerminate(application: UIApplication) { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. + } + + +} + diff --git a/Example/ActionButton/Base.lproj/Main.storyboard b/Example/ActionButton/Base.lproj/Main.storyboard new file mode 100644 index 0000000..52ea29e --- /dev/null +++ b/Example/ActionButton/Base.lproj/Main.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example/ActionButton/Images.xcassets/AppIcon.appiconset/Contents.json b/Example/ActionButton/Images.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..d3942e9 --- /dev/null +++ b/Example/ActionButton/Images.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,38 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/Example/ActionButton/Images.xcassets/googleplus_icon.imageset/Contents.json b/Example/ActionButton/Images.xcassets/googleplus_icon.imageset/Contents.json new file mode 100644 index 0000000..8217e13 --- /dev/null +++ b/Example/ActionButton/Images.xcassets/googleplus_icon.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x", + "filename" : "googleplus_icon.png" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Example/ActionButton/Images.xcassets/googleplus_icon.imageset/googleplus_icon.png b/Example/ActionButton/Images.xcassets/googleplus_icon.imageset/googleplus_icon.png new file mode 100644 index 0000000..85bdfad Binary files /dev/null and b/Example/ActionButton/Images.xcassets/googleplus_icon.imageset/googleplus_icon.png differ diff --git a/Example/ActionButton/Images.xcassets/twitter_icon.imageset/Contents.json b/Example/ActionButton/Images.xcassets/twitter_icon.imageset/Contents.json new file mode 100644 index 0000000..649a7ab --- /dev/null +++ b/Example/ActionButton/Images.xcassets/twitter_icon.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x", + "filename" : "twitter_icon.png" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Example/ActionButton/Images.xcassets/twitter_icon.imageset/twitter_icon.png b/Example/ActionButton/Images.xcassets/twitter_icon.imageset/twitter_icon.png new file mode 100644 index 0000000..d8601e6 Binary files /dev/null and b/Example/ActionButton/Images.xcassets/twitter_icon.imageset/twitter_icon.png differ diff --git a/Example/ActionButton/Info.plist b/Example/ActionButton/Info.plist new file mode 100644 index 0000000..2960c1d --- /dev/null +++ b/Example/ActionButton/Info.plist @@ -0,0 +1,39 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + + + diff --git a/Example/ActionButton/LaunchScreen.xib b/Example/ActionButton/LaunchScreen.xib new file mode 100644 index 0000000..4450587 --- /dev/null +++ b/Example/ActionButton/LaunchScreen.xib @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example/ActionButton/ViewController.swift b/Example/ActionButton/ViewController.swift new file mode 100644 index 0000000..bd7a903 --- /dev/null +++ b/Example/ActionButton/ViewController.swift @@ -0,0 +1,31 @@ +// +// ViewController.swift +// ActionButton +// +// Created by Lourenço Marinho on 05/25/2015. +// Copyright (c) 05/25/2015 Lourenço Marinho. All rights reserved. +// + +import UIKit + +class ViewController: UIViewController { + + var actionButton: ActionButton! + + override func viewDidLoad() { + super.viewDidLoad() + + let twitterImage = UIImage(named: "twitter_icon.png")! + let plusImage = UIImage(named: "googleplus_icon.png")! + + let twitter = ActionButtonItem(title: "Twitter", image: twitterImage) + twitter.action = { item in println("Twitter...") } + + let google = ActionButtonItem(title: "Google Plus", image: plusImage) + google.action = { item in println("Google Plus...") } + + actionButton = ActionButton(attachedToView: self.view, items: [twitter, google]) + actionButton.action = { button in button.toggleMenu() } + } +} + diff --git a/Example/Podfile b/Example/Podfile new file mode 100644 index 0000000..b845014 --- /dev/null +++ b/Example/Podfile @@ -0,0 +1,12 @@ +source 'https://github.com/CocoaPods/Specs.git' +use_frameworks! + +target 'ActionButton_Example', :exclusive => true do + pod "ActionButton", :path => "../" +end + +target 'Tests', :exclusive => true do + pod "ActionButton", :path => "../" + + +end diff --git a/Example/Source/.DS_Store b/Example/Source/.DS_Store new file mode 100644 index 0000000..4bba6c0 Binary files /dev/null and b/Example/Source/.DS_Store differ diff --git a/Example/Source/ActionButton.swift b/Example/Source/ActionButton.swift new file mode 100755 index 0000000..67b60bd --- /dev/null +++ b/Example/Source/ActionButton.swift @@ -0,0 +1,204 @@ +// ActionButton.swift +// +// The MIT License (MIT) +// +// Copyright (c) 2015 ActionButton +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import UIKit + +typealias ActionButtonAction = (ActionButton) -> Void + +public class ActionButton: NSObject { + + var active: Bool = false + var action: ActionButtonAction? + var items: [ActionButtonItem]? + var backgroundColor: UIColor? { + willSet { + floatButton.backgroundColor = newValue + } + } + + private var floatButton: UIButton! + private var contentView: UIView! + private var parentView: UIView! + private var blurVisualEffect: UIVisualEffectView! + private let itemOffset = -55 + private let floatButtonRadius = 50 + + public init(attachedToView view: UIView, items: [ActionButtonItem]?) { + super.init() + + self.parentView = view + self.items = items + let bounds = self.parentView.bounds + + self.floatButton = UIButton.buttonWithType(.Custom) as! UIButton + self.floatButton.layer.cornerRadius = CGFloat(floatButtonRadius / 2) + self.floatButton.layer.shadowOpacity = 1 + self.floatButton.layer.shadowRadius = 2 + self.floatButton.layer.shadowOffset = CGSize(width: 1, height: 1) + self.floatButton.layer.shadowColor = UIColor.grayColor().CGColor + self.floatButton.setTitle("+", forState: .Normal) + self.floatButton.backgroundColor = UIColor(red: 238.0/255.0, green: 130.0/255.0, blue: 34.0/255.0, alpha:1.0) + self.floatButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 8, right: 0) + self.floatButton.titleLabel!.font = UIFont(name: "HelveticaNeue-Light", size: 35) + self.floatButton.userInteractionEnabled = true + self.floatButton.setTranslatesAutoresizingMaskIntoConstraints(false) + + self.floatButton.addTarget(self, action: Selector("buttonTapped:"), forControlEvents: .TouchUpInside) + self.floatButton.addTarget(self, action: Selector("buttonTouchDown:"), forControlEvents: .TouchDown) + self.parentView.addSubview(self.floatButton) + + self.contentView = UIView(frame: bounds) + self.blurVisualEffect = UIVisualEffectView(effect: UIBlurEffect(style: .ExtraLight)) + self.blurVisualEffect.frame = self.contentView.frame + self.contentView.addSubview(self.blurVisualEffect) + + let tap = UITapGestureRecognizer(target: self, action: Selector("backgroundTapped:")) + self.contentView.addGestureRecognizer(tap) + + self.installConstraints() + } + + required public init(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + // MARK: - Auto Layout Methods + + private func installConstraints() { + let views = ["floatButton":self.floatButton, "parentView":self.parentView] + let width = NSLayoutConstraint.constraintsWithVisualFormat("H:[floatButton(\(floatButtonRadius))]", options: nil, metrics: nil, views: views) + let height = NSLayoutConstraint.constraintsWithVisualFormat("V:[floatButton(\(floatButtonRadius))]", options: nil, metrics: nil, views: views) + self.floatButton.addConstraints(width) + self.floatButton.addConstraints(height) + + let trailingSpacing = NSLayoutConstraint.constraintsWithVisualFormat("V:[floatButton]-15-|", options: nil, metrics: nil, views: views) + let bottomSpacing = NSLayoutConstraint.constraintsWithVisualFormat("H:[floatButton]-15-|", options: nil, metrics: nil, views: views) + self.parentView.addConstraints(trailingSpacing) + self.parentView.addConstraints(bottomSpacing) + } + + // MARK: - Button Actions Methods + + func buttonTapped(sender: UIControl) { + animatePressingWithScale(1.0) + + if let unwrappedAction = self.action { + unwrappedAction(self) + } + } + + func buttonTouchDown(sender: UIButton) { + animatePressingWithScale(0.9) + } + + // MARK: - Gesture Recognizer Methods + + func backgroundTapped(gesture: UIGestureRecognizer) { + if self.active { + self.toggle() + } + } + + // MARK: - Custom Methods + func toggleMenu() { + self.placeButtonItems() + self.toggle() + } + + // MARK: - Float Button Items Placement + + private func placeButtonItems() { + if let optionalItems = self.items { + for item in optionalItems { + item.view.center = CGPoint(x: self.floatButton.center.x - 83, y: self.floatButton.center.y) + item.view.removeFromSuperview() + + self.contentView.addSubview(item.view) + } + } + } + + // MARK - Float Menu Methods + + private func toggle() { + self.animateMenu() + self.showBlur() + + self.active = !self.active + } + + private func animateMenu() { + let rotation = self.active ? 0 : CGFloat(M_PI_4) + + UIView.animateWithDuration(0.3, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0.1, options: nil, animations: { + self.floatButton.transform = CGAffineTransformMakeRotation(rotation) + + if self.active == false { + self.contentView.alpha = 1.0 + + if let optionalItems = self.items { + for (index, item) in enumerate(optionalItems) { + let offset = index + 1 + let translation = self.itemOffset * offset + item.view.transform = CGAffineTransformMakeTranslation(0, CGFloat(translation)) + item.view.alpha = 1 + } + } + } else { + self.contentView.alpha = 0.0 + + if let optionalItems = self.items { + for item in optionalItems { + item.view.transform = CGAffineTransformMakeTranslation(0, 0) + item.view.alpha = 0 + } + } + } + }, completion: {completed in + if self.active == false { + self.hideBlur() + } + }) + } + + private func animateClick() { + UIView.animateWithDuration(0.3, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0.1, options: .Repeat | .Autoreverse, animations: { + self.floatButton.transform = CGAffineTransformMakeScale(1.2, 1.2) + }, completion: nil) + } + + private func showBlur() { + self.parentView.insertSubview(self.contentView, belowSubview: self.floatButton) + } + + private func hideBlur() { + self.contentView.removeFromSuperview() + } + + private func animatePressingWithScale(scale: CGFloat) { + UIView.animateWithDuration(0.2, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0.1, options: nil, animations: { + self.floatButton.transform = CGAffineTransformMakeScale(scale, scale) + }, completion: nil) + } +} diff --git a/Example/Source/ActionButtonItem.swift b/Example/Source/ActionButtonItem.swift new file mode 100755 index 0000000..690b625 --- /dev/null +++ b/Example/Source/ActionButtonItem.swift @@ -0,0 +1,124 @@ +// ActionButton.swift +// +// The MIT License (MIT) +// +// Copyright (c) 2015 ActionButton +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import UIKit + +typealias ActionButtonItemAction = (ActionButtonItem) -> Void + +public class ActionButtonItem: NSObject { + + var action: ActionButtonItemAction? + var view: UIView! + var text: String { + get { + return self.label.text! + } + + set { + self.label.text = newValue + } + } + + private var label: UILabel! + private var button: UIButton! + private var image: UIImage! + private var labelBackground: UIView! + private let viewSize = CGSize(width: 200, height: 35) + private let buttonSize = CGSize(width: 35, height: 35) + private let backgroundInset = CGSize(width: 10, height: 10) + + public init(title optionalTitle: String?, image: UIImage?) { + super.init() + + self.view = UIView(frame: CGRect(origin: CGPointZero, size: self.viewSize)) + self.view.alpha = 0 + self.view.userInteractionEnabled = true + self.view.backgroundColor = UIColor.clearColor() + + self.button = UIButton.buttonWithType(.Custom) as! UIButton + self.button.frame = CGRect(origin: CGPoint(x: self.viewSize.width - self.buttonSize.width, y: 0), size: buttonSize) + self.button.layer.shadowOpacity = 1 + self.button.layer.shadowRadius = 2 + self.button.layer.shadowOffset = CGSize(width: 1, height: 1) + self.button.layer.shadowColor = UIColor.grayColor().CGColor + self.button.addTarget(self, action: "buttonPressed:", forControlEvents: .TouchUpInside) + + if let unwrappedImage = image { + self.button.setImage(unwrappedImage, forState: .Normal) + } + + if let text = optionalTitle where text.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet()).isEmpty == false { + self.label = UILabel() + self.label.font = UIFont(name: "HelveticaNeue-Medium", size: 13) + self.label.textColor = UIColor.darkGrayColor() + self.label.textAlignment = .Right + self.label.text = text + self.label.addGestureRecognizer(UITapGestureRecognizer(target: self, action: Selector("labelTapped:"))) + self.label.sizeToFit() + + self.labelBackground = UIView() + self.labelBackground.frame = self.label.frame + self.labelBackground.backgroundColor = UIColor.whiteColor() + self.labelBackground.layer.cornerRadius = 3 + self.labelBackground.layer.shadowOpacity = 0.8 + self.labelBackground.layer.shadowOffset = CGSize(width: 0, height: 1) + self.labelBackground.layer.shadowRadius = 0.2 + self.labelBackground.layer.shadowColor = UIColor.lightGrayColor().CGColor + + // Adjust the label's background inset + self.labelBackground.frame.size.width = self.label.frame.size.width + backgroundInset.width + self.labelBackground.frame.size.height = self.label.frame.size.height + backgroundInset.height + self.label.frame.origin.x = self.label.frame.origin.x + backgroundInset.width / 2 + self.label.frame.origin.y = self.label.frame.origin.y + backgroundInset.height / 2 + + // Adjust label's background position + self.labelBackground.frame.origin.x = CGFloat(130 - self.label.frame.size.width) + self.labelBackground.center.y = self.view.center.y + self.labelBackground.addSubview(self.label) + + // Add Tap Gestures Recognizer + let tap = UITapGestureRecognizer(target: self, action: Selector("labelTapped:")) + self.view.addGestureRecognizer(tap) + + self.view.addSubview(self.labelBackground) + } + + self.view.addSubview(self.button) + } + + // MARK: - Button Action Methods + + func buttonPressed(sender: UIButton) { + if let unwrappedAction = self.action { + unwrappedAction(self) + } + } + + // MARK: - Gesture Recognizer Methods + func labelTapped(gesture: UIGestureRecognizer) { + if let unwrappedAction = self.action { + unwrappedAction(self) + } + } +} diff --git a/Example/Tests/.DS_Store b/Example/Tests/.DS_Store new file mode 100644 index 0000000..a09b53a Binary files /dev/null and b/Example/Tests/.DS_Store differ diff --git a/Example/Tests/Info.plist b/Example/Tests/Info.plist new file mode 100644 index 0000000..ee0a311 --- /dev/null +++ b/Example/Tests/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + org.cocoapods.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/Example/Tests/Tests.swift b/Example/Tests/Tests.swift new file mode 100644 index 0000000..d670933 --- /dev/null +++ b/Example/Tests/Tests.swift @@ -0,0 +1,28 @@ +import UIKit +import XCTest + +class Tests: XCTestCase { + + override func setUp() { + super.setUp() + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } + + func testExample() { + // This is an example of a functional test case. + XCTAssert(true, "Pass") + } + + func testPerformanceExample() { + // This is an example of a performance test case. + self.measureBlock() { + // Put the code you want to measure the time of here. + } + } + +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a79c117 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2015 Lourenço Marinho + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..1333eb3 --- /dev/null +++ b/README.md @@ -0,0 +1,58 @@ +![Action Button](Action Button.png) + +Action button is a Floating Action Button inspired from Google Inbox implemented in Swift + +Import +-- +You can use [CocoaPods](https://cocoapods.org/) to integrate Action Button in your project. +You can install it with the following command + +``` +$ gem install cocoapods +``` + +Update your ```Podfile``` to use Action Button + +``` +pod 'ActionButton' +``` +Then, run the following command + +``` +$ pod install +``` + +Usage +-- + +#### Define your actions +```swift +let share = ActionButtonItem(title: "share", image: shareImage) +share.action = { item in println("Sharing...") } + +let email = ActionButtonItem(title: "email", image: emailImage) +email.action = { item in println("Email...") } +``` + +#### Create a Action Button with your actions +```swift +actionButton = ActionButton(attachedToView: view, items: [share, email]) +actionButton.action = { button in button.toggleMenu() } +``` + +## Give it a try +You can try Action Button with CocoaPods +``` +$ pod try ActionButton +``` +Who to blame +-- +- [Lourenço Marinho](http://github.com/lourenco-marinho) ([@lopima](https://twitter.com/lopima)) + +More +-- +Action Button is a working in progress so feel free to fork this project and improve it! + +License +-- +Action Button is released under the MIT license. See LICENSE for details. diff --git a/Source/.DS_Store b/Source/.DS_Store new file mode 100644 index 0000000..02c143e Binary files /dev/null and b/Source/.DS_Store differ diff --git a/Source/ActionButton.swift b/Source/ActionButton.swift new file mode 100755 index 0000000..67b60bd --- /dev/null +++ b/Source/ActionButton.swift @@ -0,0 +1,204 @@ +// ActionButton.swift +// +// The MIT License (MIT) +// +// Copyright (c) 2015 ActionButton +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import UIKit + +typealias ActionButtonAction = (ActionButton) -> Void + +public class ActionButton: NSObject { + + var active: Bool = false + var action: ActionButtonAction? + var items: [ActionButtonItem]? + var backgroundColor: UIColor? { + willSet { + floatButton.backgroundColor = newValue + } + } + + private var floatButton: UIButton! + private var contentView: UIView! + private var parentView: UIView! + private var blurVisualEffect: UIVisualEffectView! + private let itemOffset = -55 + private let floatButtonRadius = 50 + + public init(attachedToView view: UIView, items: [ActionButtonItem]?) { + super.init() + + self.parentView = view + self.items = items + let bounds = self.parentView.bounds + + self.floatButton = UIButton.buttonWithType(.Custom) as! UIButton + self.floatButton.layer.cornerRadius = CGFloat(floatButtonRadius / 2) + self.floatButton.layer.shadowOpacity = 1 + self.floatButton.layer.shadowRadius = 2 + self.floatButton.layer.shadowOffset = CGSize(width: 1, height: 1) + self.floatButton.layer.shadowColor = UIColor.grayColor().CGColor + self.floatButton.setTitle("+", forState: .Normal) + self.floatButton.backgroundColor = UIColor(red: 238.0/255.0, green: 130.0/255.0, blue: 34.0/255.0, alpha:1.0) + self.floatButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 8, right: 0) + self.floatButton.titleLabel!.font = UIFont(name: "HelveticaNeue-Light", size: 35) + self.floatButton.userInteractionEnabled = true + self.floatButton.setTranslatesAutoresizingMaskIntoConstraints(false) + + self.floatButton.addTarget(self, action: Selector("buttonTapped:"), forControlEvents: .TouchUpInside) + self.floatButton.addTarget(self, action: Selector("buttonTouchDown:"), forControlEvents: .TouchDown) + self.parentView.addSubview(self.floatButton) + + self.contentView = UIView(frame: bounds) + self.blurVisualEffect = UIVisualEffectView(effect: UIBlurEffect(style: .ExtraLight)) + self.blurVisualEffect.frame = self.contentView.frame + self.contentView.addSubview(self.blurVisualEffect) + + let tap = UITapGestureRecognizer(target: self, action: Selector("backgroundTapped:")) + self.contentView.addGestureRecognizer(tap) + + self.installConstraints() + } + + required public init(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + // MARK: - Auto Layout Methods + + private func installConstraints() { + let views = ["floatButton":self.floatButton, "parentView":self.parentView] + let width = NSLayoutConstraint.constraintsWithVisualFormat("H:[floatButton(\(floatButtonRadius))]", options: nil, metrics: nil, views: views) + let height = NSLayoutConstraint.constraintsWithVisualFormat("V:[floatButton(\(floatButtonRadius))]", options: nil, metrics: nil, views: views) + self.floatButton.addConstraints(width) + self.floatButton.addConstraints(height) + + let trailingSpacing = NSLayoutConstraint.constraintsWithVisualFormat("V:[floatButton]-15-|", options: nil, metrics: nil, views: views) + let bottomSpacing = NSLayoutConstraint.constraintsWithVisualFormat("H:[floatButton]-15-|", options: nil, metrics: nil, views: views) + self.parentView.addConstraints(trailingSpacing) + self.parentView.addConstraints(bottomSpacing) + } + + // MARK: - Button Actions Methods + + func buttonTapped(sender: UIControl) { + animatePressingWithScale(1.0) + + if let unwrappedAction = self.action { + unwrappedAction(self) + } + } + + func buttonTouchDown(sender: UIButton) { + animatePressingWithScale(0.9) + } + + // MARK: - Gesture Recognizer Methods + + func backgroundTapped(gesture: UIGestureRecognizer) { + if self.active { + self.toggle() + } + } + + // MARK: - Custom Methods + func toggleMenu() { + self.placeButtonItems() + self.toggle() + } + + // MARK: - Float Button Items Placement + + private func placeButtonItems() { + if let optionalItems = self.items { + for item in optionalItems { + item.view.center = CGPoint(x: self.floatButton.center.x - 83, y: self.floatButton.center.y) + item.view.removeFromSuperview() + + self.contentView.addSubview(item.view) + } + } + } + + // MARK - Float Menu Methods + + private func toggle() { + self.animateMenu() + self.showBlur() + + self.active = !self.active + } + + private func animateMenu() { + let rotation = self.active ? 0 : CGFloat(M_PI_4) + + UIView.animateWithDuration(0.3, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0.1, options: nil, animations: { + self.floatButton.transform = CGAffineTransformMakeRotation(rotation) + + if self.active == false { + self.contentView.alpha = 1.0 + + if let optionalItems = self.items { + for (index, item) in enumerate(optionalItems) { + let offset = index + 1 + let translation = self.itemOffset * offset + item.view.transform = CGAffineTransformMakeTranslation(0, CGFloat(translation)) + item.view.alpha = 1 + } + } + } else { + self.contentView.alpha = 0.0 + + if let optionalItems = self.items { + for item in optionalItems { + item.view.transform = CGAffineTransformMakeTranslation(0, 0) + item.view.alpha = 0 + } + } + } + }, completion: {completed in + if self.active == false { + self.hideBlur() + } + }) + } + + private func animateClick() { + UIView.animateWithDuration(0.3, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0.1, options: .Repeat | .Autoreverse, animations: { + self.floatButton.transform = CGAffineTransformMakeScale(1.2, 1.2) + }, completion: nil) + } + + private func showBlur() { + self.parentView.insertSubview(self.contentView, belowSubview: self.floatButton) + } + + private func hideBlur() { + self.contentView.removeFromSuperview() + } + + private func animatePressingWithScale(scale: CGFloat) { + UIView.animateWithDuration(0.2, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0.1, options: nil, animations: { + self.floatButton.transform = CGAffineTransformMakeScale(scale, scale) + }, completion: nil) + } +} diff --git a/Source/ActionButtonItem.swift b/Source/ActionButtonItem.swift new file mode 100755 index 0000000..690b625 --- /dev/null +++ b/Source/ActionButtonItem.swift @@ -0,0 +1,124 @@ +// ActionButton.swift +// +// The MIT License (MIT) +// +// Copyright (c) 2015 ActionButton +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import UIKit + +typealias ActionButtonItemAction = (ActionButtonItem) -> Void + +public class ActionButtonItem: NSObject { + + var action: ActionButtonItemAction? + var view: UIView! + var text: String { + get { + return self.label.text! + } + + set { + self.label.text = newValue + } + } + + private var label: UILabel! + private var button: UIButton! + private var image: UIImage! + private var labelBackground: UIView! + private let viewSize = CGSize(width: 200, height: 35) + private let buttonSize = CGSize(width: 35, height: 35) + private let backgroundInset = CGSize(width: 10, height: 10) + + public init(title optionalTitle: String?, image: UIImage?) { + super.init() + + self.view = UIView(frame: CGRect(origin: CGPointZero, size: self.viewSize)) + self.view.alpha = 0 + self.view.userInteractionEnabled = true + self.view.backgroundColor = UIColor.clearColor() + + self.button = UIButton.buttonWithType(.Custom) as! UIButton + self.button.frame = CGRect(origin: CGPoint(x: self.viewSize.width - self.buttonSize.width, y: 0), size: buttonSize) + self.button.layer.shadowOpacity = 1 + self.button.layer.shadowRadius = 2 + self.button.layer.shadowOffset = CGSize(width: 1, height: 1) + self.button.layer.shadowColor = UIColor.grayColor().CGColor + self.button.addTarget(self, action: "buttonPressed:", forControlEvents: .TouchUpInside) + + if let unwrappedImage = image { + self.button.setImage(unwrappedImage, forState: .Normal) + } + + if let text = optionalTitle where text.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet()).isEmpty == false { + self.label = UILabel() + self.label.font = UIFont(name: "HelveticaNeue-Medium", size: 13) + self.label.textColor = UIColor.darkGrayColor() + self.label.textAlignment = .Right + self.label.text = text + self.label.addGestureRecognizer(UITapGestureRecognizer(target: self, action: Selector("labelTapped:"))) + self.label.sizeToFit() + + self.labelBackground = UIView() + self.labelBackground.frame = self.label.frame + self.labelBackground.backgroundColor = UIColor.whiteColor() + self.labelBackground.layer.cornerRadius = 3 + self.labelBackground.layer.shadowOpacity = 0.8 + self.labelBackground.layer.shadowOffset = CGSize(width: 0, height: 1) + self.labelBackground.layer.shadowRadius = 0.2 + self.labelBackground.layer.shadowColor = UIColor.lightGrayColor().CGColor + + // Adjust the label's background inset + self.labelBackground.frame.size.width = self.label.frame.size.width + backgroundInset.width + self.labelBackground.frame.size.height = self.label.frame.size.height + backgroundInset.height + self.label.frame.origin.x = self.label.frame.origin.x + backgroundInset.width / 2 + self.label.frame.origin.y = self.label.frame.origin.y + backgroundInset.height / 2 + + // Adjust label's background position + self.labelBackground.frame.origin.x = CGFloat(130 - self.label.frame.size.width) + self.labelBackground.center.y = self.view.center.y + self.labelBackground.addSubview(self.label) + + // Add Tap Gestures Recognizer + let tap = UITapGestureRecognizer(target: self, action: Selector("labelTapped:")) + self.view.addGestureRecognizer(tap) + + self.view.addSubview(self.labelBackground) + } + + self.view.addSubview(self.button) + } + + // MARK: - Button Action Methods + + func buttonPressed(sender: UIButton) { + if let unwrappedAction = self.action { + unwrappedAction(self) + } + } + + // MARK: - Gesture Recognizer Methods + func labelTapped(gesture: UIGestureRecognizer) { + if let unwrappedAction = self.action { + unwrappedAction(self) + } + } +}