From 230770d0d153b1d381e1c0cc1b3048e42deb3579 Mon Sep 17 00:00:00 2001 From: dodgecm Date: Wed, 13 Jul 2016 11:25:25 -0700 Subject: [PATCH 1/2] Adding title and icon support for center button. --- .../HELargeCenterTabBarController.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/HELargeCenterTabBarController/HELargeCenterTabBarController.swift b/HELargeCenterTabBarController/HELargeCenterTabBarController.swift index e9f76d3..24e8bed 100644 --- a/HELargeCenterTabBarController/HELargeCenterTabBarController.swift +++ b/HELargeCenterTabBarController/HELargeCenterTabBarController.swift @@ -126,7 +126,7 @@ class HELargeCenterTabBarController: UITabBarController { - parameter action: Optional target selector to execute when tapping the center button/tab. - parameter allowSwitch: If true, taps on the center button/tab will select that tab. If false, taps will not select (but target-action will still be executed). */ - public func addCenterButton(unselectedImage unselectedImage: UIImage, selectedImage: UIImage, target: AnyObject? = nil, action: Selector? = nil, allowSwitch: Bool = true) { + public func addCenterButton(title: String? = nil, icon: UIImage? = nil, unselectedImage: UIImage, selectedImage: UIImage, target: AnyObject? = nil, action: Selector? = nil, allowSwitch: Bool = true) { assert((target == nil && action == nil) || (target != nil && action != nil)) assert(delegate === self, "HELargeCenterTabBarController must be its own delegate") delegate = self @@ -143,8 +143,10 @@ class HELargeCenterTabBarController: UITabBarController { } let button = UIButton(type: .Custom) button.translatesAutoresizingMaskIntoConstraints = false + button.setImage(icon, forState: .Normal) + button.setTitle(title, forState: .Normal) tabBar.addSubview(button) - + view.addConstraint(NSLayoutConstraint(item: button, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.CenterX, multiplier: 1.0, constant: 0.0)); view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:[button]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["button": button])); view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:[button(==\(unselectedImage.size.width))]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["button": button])); From 611d835240ee891a72c6731199f0ecd79347a0d9 Mon Sep 17 00:00:00 2001 From: dodgecm Date: Thu, 22 Sep 2016 12:13:59 -0700 Subject: [PATCH 2/2] Swift 3 support --- .../project.pbxproj | 36 ++++++++----- ...rgeCenterTabBarController Example.xcscheme | 2 +- .../HELargeCenterTabBarController.xcscheme | 2 +- .../HELargeCenterTabBarController.swift | 52 +++++++++---------- .../AppDelegate.swift | 47 ++++++++--------- .../ModalViewController.swift | 2 +- 6 files changed, 75 insertions(+), 66 deletions(-) diff --git a/HELargeCenterTabBarController.xcodeproj/project.pbxproj b/HELargeCenterTabBarController.xcodeproj/project.pbxproj index 87a81d7..dc4a080 100644 --- a/HELargeCenterTabBarController.xcodeproj/project.pbxproj +++ b/HELargeCenterTabBarController.xcodeproj/project.pbxproj @@ -7,18 +7,18 @@ objects = { /* Begin PBXBuildFile section */ - 7901CBA11BAF0768005AE0F5 /* ModalViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7901CBA01BAF0768005AE0F5 /* ModalViewController.swift */; settings = {ASSET_TAGS = (); }; }; + 7901CBA11BAF0768005AE0F5 /* ModalViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7901CBA01BAF0768005AE0F5 /* ModalViewController.swift */; }; 7901CBAA1BAF16F0005AE0F5 /* HELargeCenterTabBarController.h in Headers */ = {isa = PBXBuildFile; fileRef = 7901CBA91BAF16F0005AE0F5 /* HELargeCenterTabBarController.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7901CBAE1BAF16F0005AE0F5 /* HELargeCenterTabBarController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7901CBA71BAF16F0005AE0F5 /* HELargeCenterTabBarController.framework */; }; 7901CBAF1BAF16F0005AE0F5 /* HELargeCenterTabBarController.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 7901CBA71BAF16F0005AE0F5 /* HELargeCenterTabBarController.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 7901CBB41BAF170D005AE0F5 /* HELargeCenterTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7901CB9E1BAEDA96005AE0F5 /* HELargeCenterTabBarController.swift */; settings = {ASSET_TAGS = (); }; }; - 7952AFA41BAEC40F00789C09 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7952AF9B1BAEC40F00789C09 /* AppDelegate.swift */; settings = {ASSET_TAGS = (); }; }; - 7952AFA51BAEC40F00789C09 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7952AF9C1BAEC40F00789C09 /* Assets.xcassets */; settings = {ASSET_TAGS = (); }; }; - 7952AFA61BAEC40F00789C09 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7952AF9D1BAEC40F00789C09 /* LaunchScreen.storyboard */; settings = {ASSET_TAGS = (); }; }; - 7952AFA71BAEC40F00789C09 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7952AF9F1BAEC40F00789C09 /* Main.storyboard */; settings = {ASSET_TAGS = (); }; }; - 7952AFA81BAEC40F00789C09 /* FirstViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7952AFA11BAEC40F00789C09 /* FirstViewController.swift */; settings = {ASSET_TAGS = (); }; }; - 7952AFAA1BAEC40F00789C09 /* SecondViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7952AFA31BAEC40F00789C09 /* SecondViewController.swift */; settings = {ASSET_TAGS = (); }; }; - 7952AFB01BAEC59800789C09 /* ThirdViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7952AFAF1BAEC59800789C09 /* ThirdViewController.swift */; settings = {ASSET_TAGS = (); }; }; + 7901CBB41BAF170D005AE0F5 /* HELargeCenterTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7901CB9E1BAEDA96005AE0F5 /* HELargeCenterTabBarController.swift */; }; + 7952AFA41BAEC40F00789C09 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7952AF9B1BAEC40F00789C09 /* AppDelegate.swift */; }; + 7952AFA51BAEC40F00789C09 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7952AF9C1BAEC40F00789C09 /* Assets.xcassets */; }; + 7952AFA61BAEC40F00789C09 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7952AF9D1BAEC40F00789C09 /* LaunchScreen.storyboard */; }; + 7952AFA71BAEC40F00789C09 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7952AF9F1BAEC40F00789C09 /* Main.storyboard */; }; + 7952AFA81BAEC40F00789C09 /* FirstViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7952AFA11BAEC40F00789C09 /* FirstViewController.swift */; }; + 7952AFAA1BAEC40F00789C09 /* SecondViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7952AFA31BAEC40F00789C09 /* SecondViewController.swift */; }; + 7952AFB01BAEC59800789C09 /* ThirdViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7952AFAF1BAEC59800789C09 /* ThirdViewController.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -185,11 +185,12 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = "Hsoi Enterprises LLC"; TargetAttributes = { 7901CBA61BAF16F0005AE0F5 = { CreatedOnToolsVersion = 7.0; + LastSwiftMigration = 0800; }; 7952AF821BAEC32E00789C09 = { CreatedOnToolsVersion = 7.0; @@ -289,6 +290,7 @@ 7901CBB11BAF16F0005AE0F5 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -300,6 +302,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.hsoienterprises.HELargeCenterTabBarController; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -308,6 +311,7 @@ 7901CBB21BAF16F0005AE0F5 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -319,6 +323,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.hsoienterprises.HELargeCenterTabBarController; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -341,8 +346,10 @@ 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_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -391,8 +398,10 @@ 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_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -421,27 +430,29 @@ 7952AF981BAEC32E00789C09 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; INFOPLIST_FILE = "$(SRCROOT)/HELargeCenterTabBarControllerExample/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.hsoienterprises.HELargeCenterTabBarControllerExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; 7952AF991BAEC32E00789C09 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; INFOPLIST_FILE = "$(SRCROOT)/HELargeCenterTabBarControllerExample/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.hsoienterprises.HELargeCenterTabBarControllerExample; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -455,6 +466,7 @@ 7901CBB21BAF16F0005AE0F5 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 7952AF7E1BAEC32D00789C09 /* Build configuration list for PBXProject "HELargeCenterTabBarController" */ = { isa = XCConfigurationList; diff --git a/HELargeCenterTabBarController.xcodeproj/xcshareddata/xcschemes/HELargeCenterTabBarController Example.xcscheme b/HELargeCenterTabBarController.xcodeproj/xcshareddata/xcschemes/HELargeCenterTabBarController Example.xcscheme index f948d00..bad4f80 100644 --- a/HELargeCenterTabBarController.xcodeproj/xcshareddata/xcschemes/HELargeCenterTabBarController Example.xcscheme +++ b/HELargeCenterTabBarController.xcodeproj/xcshareddata/xcschemes/HELargeCenterTabBarController Example.xcscheme @@ -1,6 +1,6 @@ Bool { + public func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool { var should = true if centerViewController === viewController && !allowSwitch { should = false diff --git a/HELargeCenterTabBarControllerExample/AppDelegate.swift b/HELargeCenterTabBarControllerExample/AppDelegate.swift index 21606a7..0534c0a 100644 --- a/HELargeCenterTabBarControllerExample/AppDelegate.swift +++ b/HELargeCenterTabBarControllerExample/AppDelegate.swift @@ -12,61 +12,60 @@ import HELargeCenterTabBarController @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { - + var window: UIWindow? - - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { - + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { + if let tabBarController = window?.rootViewController as? HELargeCenterTabBarController { - // Hsoi 2015-09-20 - At this point the OS hasn't yet loaded the tab view (HELargeCenterTabBarController.viewDidLoad() + // Hsoi 2015-09-20 - At this point the OS hasn't yet loaded the tab view (HELargeCenterTabBarController.viewDidLoad() // hasn't yet been called). So we'll let things go around the block once and then we'll load it all up. - dispatch_async(dispatch_get_main_queue(), { () -> Void in - if let unselectedImage = UIImage(named: "tab-unselected"), selectedImage = UIImage(named: "tab-selected") { + DispatchQueue.main.async { + if let unselectedImage = UIImage(named: "tab-unselected"), let selectedImage = UIImage(named: "tab-selected") { // Hsoi 2015-09-20 - Comment/Uncomment one line or the other to see how `allowSwitch works. - tabBarController.addCenterButton(unselectedImage: unselectedImage, selectedImage: selectedImage) //tabBarController.addCenterButton(unselectedImage: unselectedImage, selectedImage: selectedImage, target: self, action: "presentSecondViewController:", allowSwitch: false) } - }) + } } return true } - - func applicationWillResignActive(application: UIApplication) { + + 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) { + + 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) { + + 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) { + + 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) { + + func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } - - + + // MARK: - func presentSecondViewController(sender: AnyObject) { if let rootViewController = window?.rootViewController { - let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("modalNavViewController") - rootViewController.presentViewController(viewController, animated: true, completion: nil) + let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "modalNavViewController") + rootViewController.present(viewController, animated: true, completion: nil) } } - + } diff --git a/HELargeCenterTabBarControllerExample/ModalViewController.swift b/HELargeCenterTabBarControllerExample/ModalViewController.swift index 4454295..a3e10ba 100644 --- a/HELargeCenterTabBarControllerExample/ModalViewController.swift +++ b/HELargeCenterTabBarControllerExample/ModalViewController.swift @@ -23,7 +23,7 @@ class ModalViewController: UIViewController { @IBAction func dismissMyself(sender: AnyObject) { - dismissViewControllerAnimated(true, completion: nil) + dismiss(animated: true, completion: nil) } /*