From e4f868f2e23a0d9c26126d6a9c33e96126d33026 Mon Sep 17 00:00:00 2001 From: edasandesu Date: Mon, 14 Oct 2019 11:26:11 +0900 Subject: [PATCH 1/3] update to iOS13 and Swift 5 --- .../ActionButton.xcodeproj/project.pbxproj | 40 ++++++++++++++----- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++ .../xcschemes/ActionButton-Example.xcscheme | 24 +++++------ Example/ActionButton/AppDelegate.swift | 2 +- .../AppIcon.appiconset/Contents.json | 5 +++ Example/ActionButton/ViewController.swift | 2 +- Source/ActionButton.swift | 28 ++++++------- Source/ActionButtonItem.swift | 6 +-- 8 files changed, 72 insertions(+), 43 deletions(-) create mode 100644 Example/ActionButton.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Example/ActionButton.xcodeproj/project.pbxproj b/Example/ActionButton.xcodeproj/project.pbxproj index b0ea25a..5a40989 100644 --- a/Example/ActionButton.xcodeproj/project.pbxproj +++ b/Example/ActionButton.xcodeproj/project.pbxproj @@ -173,7 +173,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 1100; ORGANIZATIONNAME = CocoaPods; TargetAttributes = { 607FACCF1AFB9204008FA782 = { @@ -189,7 +189,7 @@ }; buildConfigurationList = 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "ActionButton" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, @@ -272,18 +272,27 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -307,7 +316,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.3; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -319,18 +328,27 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -347,7 +365,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.3; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; @@ -359,13 +377,14 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = ActionButton/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MODULE_NAME = ExampleApp; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -373,13 +392,14 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = ActionButton/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MODULE_NAME = ExampleApp; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -399,7 +419,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ActionButton_Example.app/ActionButton_Example"; }; name = Debug; @@ -416,7 +436,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ActionButton_Example.app/ActionButton_Example"; }; name = Release; diff --git a/Example/ActionButton.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Example/ActionButton.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Example/ActionButton.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Example/ActionButton.xcodeproj/xcshareddata/xcschemes/ActionButton-Example.xcscheme b/Example/ActionButton.xcodeproj/xcshareddata/xcschemes/ActionButton-Example.xcscheme index 2beac40..17913e5 100644 --- a/Example/ActionButton.xcodeproj/xcshareddata/xcschemes/ActionButton-Example.xcscheme +++ b/Example/ActionButton.xcodeproj/xcshareddata/xcschemes/ActionButton-Example.xcscheme @@ -1,6 +1,6 @@ + + + + @@ -53,17 +62,6 @@ - - - - - - - - Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } diff --git a/Example/ActionButton/Images.xcassets/AppIcon.appiconset/Contents.json b/Example/ActionButton/Images.xcassets/AppIcon.appiconset/Contents.json index b8236c6..19882d5 100644 --- a/Example/ActionButton/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/Example/ActionButton/Images.xcassets/AppIcon.appiconset/Contents.json @@ -39,6 +39,11 @@ "idiom" : "iphone", "size" : "60x60", "scale" : "3x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" } ], "info" : { diff --git a/Example/ActionButton/ViewController.swift b/Example/ActionButton/ViewController.swift index fe8d521..fe94d8e 100644 --- a/Example/ActionButton/ViewController.swift +++ b/Example/ActionButton/ViewController.swift @@ -42,7 +42,7 @@ class ViewController: UIViewController { actionButton = ActionButton(attachedToView: self.view, items: [twitter, google]) actionButton.action = { button in button.toggleMenu() } - actionButton.setTitle("+", forState: UIControlState()) + actionButton.setTitle("+", forState: UIControl.State()) actionButton.backgroundColor = UIColor(red: 238.0/255.0, green: 130.0/255.0, blue: 34.0/255.0, alpha:1.0) } diff --git a/Source/ActionButton.swift b/Source/ActionButton.swift index 39976ea..08841cf 100755 --- a/Source/ActionButton.swift +++ b/Source/ActionButton.swift @@ -89,8 +89,8 @@ open class ActionButton: NSObject { self.floatButton.layer.shadowRadius = 2 self.floatButton.layer.shadowOffset = CGSize(width: 1, height: 1) self.floatButton.layer.shadowColor = UIColor.gray.cgColor - self.floatButton.setTitle("+", for: UIControlState()) - self.floatButton.setImage(nil, for: UIControlState()) + self.floatButton.setTitle("+", for: UIControl.State()) + self.floatButton.setImage(nil, for: UIControl.State()) self.floatButton.backgroundColor = self.backgroundColor self.floatButton.titleLabel!.font = UIFont(name: "HelveticaNeue-Light", size: 35) self.floatButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 8, right: 0) @@ -117,13 +117,13 @@ open class ActionButton: NSObject { } //MARK: - Set Methods - open func setTitle(_ title: String?, forState state: UIControlState) { + open func setTitle(_ title: String?, forState state: UIControl.State) { floatButton.setImage(nil, for: state) floatButton.setTitle(title, for: state) floatButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 8, right: 0) } - open func setImage(_ image: UIImage?, forState state: UIControlState) { + open func setImage(_ image: UIImage?, forState state: UIControl.State) { setTitle(nil, forState: state) floatButton.setImage(image, for: state) floatButton.adjustsImageWhenHighlighted = false @@ -136,19 +136,19 @@ open class ActionButton: NSObject { */ fileprivate func installConstraints() { let views: [String: UIView] = ["floatButton":self.floatButton, "parentView":self.parentView] - let width = NSLayoutConstraint.constraints(withVisualFormat: "H:[floatButton(\(floatButtonRadius))]", options: NSLayoutFormatOptions.alignAllCenterX, metrics: nil, views: views) - let height = NSLayoutConstraint.constraints(withVisualFormat: "V:[floatButton(\(floatButtonRadius))]", options: NSLayoutFormatOptions.alignAllCenterX, metrics: nil, views: views) + let width = NSLayoutConstraint.constraints(withVisualFormat: "H:[floatButton(\(floatButtonRadius))]", options: NSLayoutConstraint.FormatOptions.alignAllCenterX, metrics: nil, views: views) + let height = NSLayoutConstraint.constraints(withVisualFormat: "V:[floatButton(\(floatButtonRadius))]", options: NSLayoutConstraint.FormatOptions.alignAllCenterX, metrics: nil, views: views) self.floatButton.addConstraints(width) self.floatButton.addConstraints(height) - let trailingSpacing = NSLayoutConstraint.constraints(withVisualFormat: "V:[floatButton]-15-|", options: NSLayoutFormatOptions.alignAllCenterX, metrics: nil, views: views) - let bottomSpacing = NSLayoutConstraint.constraints(withVisualFormat: "H:[floatButton]-15-|", options: NSLayoutFormatOptions.alignAllCenterX, metrics: nil, views: views) + let trailingSpacing = NSLayoutConstraint.constraints(withVisualFormat: "V:[floatButton]-15-|", options: NSLayoutConstraint.FormatOptions.alignAllCenterX, metrics: nil, views: views) + let bottomSpacing = NSLayoutConstraint.constraints(withVisualFormat: "H:[floatButton]-15-|", options: NSLayoutConstraint.FormatOptions.alignAllCenterX, metrics: nil, views: views) self.parentView.addConstraints(trailingSpacing) self.parentView.addConstraints(bottomSpacing) } //MARK: - Button Actions Methods - func buttonTapped(_ sender: UIControl) { + @objc func buttonTapped(_ sender: UIControl) { animatePressingWithScale(1.0) if let unwrappedAction = self.action { @@ -156,12 +156,12 @@ open class ActionButton: NSObject { } } - func buttonTouchDown(_ sender: UIButton) { + @objc func buttonTouchDown(_ sender: UIButton) { animatePressingWithScale(0.9) } //MARK: - Gesture Recognizer Methods - func backgroundTapped(_ gesture: UIGestureRecognizer) { + @objc func backgroundTapped(_ gesture: UIGestureRecognizer) { if self.active { self.toggle() } @@ -205,9 +205,9 @@ open class ActionButton: NSObject { } fileprivate func animateMenu() { - let rotation = self.active ? 0 : CGFloat(M_PI_4) + let rotation = self.active ? 0 : CGFloat(Double.pi / 4) - UIView.animate(withDuration: 0.3, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0.1, options: UIViewAnimationOptions.allowAnimatedContent, animations: { + UIView.animate(withDuration: 0.3, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0.1, options: UIView.AnimationOptions.allowAnimatedContent, animations: { if self.floatButton.imageView?.image == nil { self.floatButton.transform = CGAffineTransform(rotationAngle: rotation) @@ -259,7 +259,7 @@ open class ActionButton: NSObject { - parameter scale: how much the button should be scaled */ fileprivate func animatePressingWithScale(_ scale: CGFloat) { - UIView.animate(withDuration: 0.2, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0.1, options: UIViewAnimationOptions.allowAnimatedContent, animations: { + UIView.animate(withDuration: 0.2, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0.1, options: UIView.AnimationOptions.allowAnimatedContent, animations: { self.floatButton.transform = CGAffineTransform(scaleX: scale, y: scale) }, completion: nil) } diff --git a/Source/ActionButtonItem.swift b/Source/ActionButtonItem.swift index 3709793..8b7fcc0 100755 --- a/Source/ActionButtonItem.swift +++ b/Source/ActionButtonItem.swift @@ -83,7 +83,7 @@ open class ActionButtonItem: NSObject { self.button.addTarget(self, action: #selector(ActionButtonItem.buttonPressed(_:)), for: .touchUpInside) if let unwrappedImage = image { - self.button.setImage(unwrappedImage, for: UIControlState()) + self.button.setImage(unwrappedImage, for: UIControl.State()) } if let text = optionalTitle , text.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty == false { @@ -126,14 +126,14 @@ open class ActionButtonItem: NSObject { } //MARK: - Button Action Methods - func buttonPressed(_ sender: UIButton) { + @objc func buttonPressed(_ sender: UIButton) { if let unwrappedAction = self.action { unwrappedAction(self) } } //MARK: - Gesture Recognizer Methods - func labelTapped(_ gesture: UIGestureRecognizer) { + @objc func labelTapped(_ gesture: UIGestureRecognizer) { if let unwrappedAction = self.action { unwrappedAction(self) } From c1beb93e7b4981003c0c813475b5f7978beb1c3a Mon Sep 17 00:00:00 2001 From: edasandesu Date: Mon, 14 Oct 2019 13:22:33 +0900 Subject: [PATCH 2/3] trailingSpacing and bottomSpacing is reversed --- Source/ActionButton.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/ActionButton.swift b/Source/ActionButton.swift index 08841cf..ad8ed48 100755 --- a/Source/ActionButton.swift +++ b/Source/ActionButton.swift @@ -141,8 +141,8 @@ open class ActionButton: NSObject { self.floatButton.addConstraints(width) self.floatButton.addConstraints(height) - let trailingSpacing = NSLayoutConstraint.constraints(withVisualFormat: "V:[floatButton]-15-|", options: NSLayoutConstraint.FormatOptions.alignAllCenterX, metrics: nil, views: views) - let bottomSpacing = NSLayoutConstraint.constraints(withVisualFormat: "H:[floatButton]-15-|", options: NSLayoutConstraint.FormatOptions.alignAllCenterX, metrics: nil, views: views) + let trailingSpacing = NSLayoutConstraint.constraints(withVisualFormat: "H:[floatButton]-15-|", options: NSLayoutConstraint.FormatOptions.alignAllCenterX, metrics: nil, views: views) + let bottomSpacing = NSLayoutConstraint.constraints(withVisualFormat: "V:[floatButton]-150-|", options: NSLayoutConstraint.FormatOptions.alignAllCenterX, metrics: nil, views: views) self.parentView.addConstraints(trailingSpacing) self.parentView.addConstraints(bottomSpacing) } From a573163f2559e201e49f4c2c2ca2e21327797d0f Mon Sep 17 00:00:00 2001 From: edasandesu Date: Mon, 14 Oct 2019 13:32:17 +0900 Subject: [PATCH 3/3] Added a parameter to set the button position --- Example/ActionButton/ViewController.swift | 2 +- Source/ActionButton.swift | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Example/ActionButton/ViewController.swift b/Example/ActionButton/ViewController.swift index fe94d8e..1800127 100644 --- a/Example/ActionButton/ViewController.swift +++ b/Example/ActionButton/ViewController.swift @@ -40,7 +40,7 @@ class ViewController: UIViewController { let google = ActionButtonItem(title: "Google Plus", image: plusImage) google.action = { item in print("Google Plus...") } - actionButton = ActionButton(attachedToView: self.view, items: [twitter, google]) + actionButton = ActionButton(attachedToView: self.view, items: [twitter, google], trailingOffset: 20, bottomOffset: 50) actionButton.action = { button in button.toggleMenu() } actionButton.setTitle("+", forState: UIControl.State()) diff --git a/Source/ActionButton.swift b/Source/ActionButton.swift index ad8ed48..773be91 100755 --- a/Source/ActionButton.swift +++ b/Source/ActionButton.swift @@ -76,7 +76,7 @@ open class ActionButton: NSObject { /// the float button's radius fileprivate let floatButtonRadius = 50 - public init(attachedToView view: UIView, items: [ActionButtonItem]?) { + public init(attachedToView view: UIView, items: [ActionButtonItem]?, trailingOffset: CGFloat = 15, bottomOffset: CGFloat = 15) { super.init() self.parentView = view @@ -109,7 +109,7 @@ open class ActionButton: NSObject { let tap = UITapGestureRecognizer(target: self, action: #selector(ActionButton.backgroundTapped(_:))) self.contentView.addGestureRecognizer(tap) - self.installConstraints() + self.installConstraints(trailingOffset, bottomOffset) } required public init(coder aDecoder: NSCoder) { @@ -134,15 +134,15 @@ open class ActionButton: NSObject { /** Install all the necessary constraints for the button. By the default the button will be placed at 15pts from the bottom and the 15pts from the right of its *parentView* */ - fileprivate func installConstraints() { + fileprivate func installConstraints(_ trailingOffset: CGFloat = 15, _ bottomOffset: CGFloat = 15) { let views: [String: UIView] = ["floatButton":self.floatButton, "parentView":self.parentView] let width = NSLayoutConstraint.constraints(withVisualFormat: "H:[floatButton(\(floatButtonRadius))]", options: NSLayoutConstraint.FormatOptions.alignAllCenterX, metrics: nil, views: views) let height = NSLayoutConstraint.constraints(withVisualFormat: "V:[floatButton(\(floatButtonRadius))]", options: NSLayoutConstraint.FormatOptions.alignAllCenterX, metrics: nil, views: views) self.floatButton.addConstraints(width) self.floatButton.addConstraints(height) - let trailingSpacing = NSLayoutConstraint.constraints(withVisualFormat: "H:[floatButton]-15-|", options: NSLayoutConstraint.FormatOptions.alignAllCenterX, metrics: nil, views: views) - let bottomSpacing = NSLayoutConstraint.constraints(withVisualFormat: "V:[floatButton]-150-|", options: NSLayoutConstraint.FormatOptions.alignAllCenterX, metrics: nil, views: views) + let trailingSpacing = NSLayoutConstraint.constraints(withVisualFormat: "H:[floatButton]-\(trailingOffset)-|", options: NSLayoutConstraint.FormatOptions.alignAllCenterX, metrics: nil, views: views) + let bottomSpacing = NSLayoutConstraint.constraints(withVisualFormat: "V:[floatButton]-\(bottomOffset)-|", options: NSLayoutConstraint.FormatOptions.alignAllCenterX, metrics: nil, views: views) self.parentView.addConstraints(trailingSpacing) self.parentView.addConstraints(bottomSpacing) }