Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #8 from dodgecm/swift-3
Browse files Browse the repository at this point in the history
Swift 3 compatability
  • Loading branch information
hsoi authored Sep 24, 2016
2 parents 07975b5 + 611d835 commit 8af0e32
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 65 deletions.
36 changes: 24 additions & 12 deletions HELargeCenterTabBarController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 = "";
};
Expand All @@ -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;
Expand All @@ -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 = "";
};
Expand All @@ -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";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;
};
Expand All @@ -455,6 +466,7 @@
7901CBB21BAF16F0005AE0F5 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
7952AF7E1BAEC32D00789C09 /* Build configuration list for PBXProject "HELargeCenterTabBarController" */ = {
isa = XCConfigurationList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
52 changes: 26 additions & 26 deletions HELargeCenterTabBarController/HELargeCenterTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,53 +60,53 @@ unselected. If for some reason you must use the same image for both states, then
pass the same `UIImage` for both states.
*/

public
open
class HELargeCenterTabBarController: UITabBarController {


/**
Sets `self` as the delegate.
*/
override public func viewDidLoad() {
override open func viewDidLoad() {
super.viewDidLoad()

delegate = self
}


/// Override to ensure that upon selection, the center button is updated
override public var selectedViewController: UIViewController? {
override open var selectedViewController: UIViewController? {
didSet {
updateCenterButton()
}
}


/// Override to ensure that upon selection, the center button is updated.
override public var selectedIndex: Int {
override open var selectedIndex: Int {
didSet {
updateCenterButton()
}
}


/// Reference to the center button. Marked optional, but generally should exist (else what's the point?).
private weak var centerButton: UIButton?
fileprivate weak var centerButton: UIButton?

/// Reference to the "selected" version of the button. Marked optional, but generally should exist (else what's the point?).
private var buttonImageSelected: UIImage?
fileprivate var buttonImageSelected: UIImage?

/// Reference to the "unselected" version of the button. Marked optional, but generally should exist (else what's the point?).
private var buttonImageUnselected: UIImage?
fileprivate var buttonImageUnselected: UIImage?

/// Reference to the action target. Optional, as the button doesn't have to have a target-action behavior.
private var buttonTarget: AnyObject?
fileprivate var buttonTarget: AnyObject?

/// Reference to the action selector. Optional, as the button doesn't haev to have a target-action behavior.
private var buttonAction: Selector?
fileprivate var buttonAction: Selector?

/// Does tapping/selecting the center button allow the tab controller to actually switch to that tab or not? Generally if set to false, the target-action should be set so as to have some response to the button tap.
private var allowSwitch: Bool = true
fileprivate var allowSwitch: Bool = true


/**
Expand All @@ -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(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
Expand All @@ -141,16 +141,16 @@ class HELargeCenterTabBarController: UITabBarController {
centerButton.removeFromSuperview()
self.centerButton = nil
}
let button = UIButton(type: .Custom)
let button = UIButton(type: .custom)
button.translatesAutoresizingMaskIntoConstraints = false
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]));
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:[button(==\(unselectedImage.size.height))]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["button": button]));

button.addTarget(self, action: #selector(centerButtonAction(_:)), forControlEvents: .TouchUpInside)
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.constraints(withVisualFormat: "V:[button]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["button": button]));
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:[button(==\(unselectedImage.size.width))]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["button": button]));
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:[button(==\(unselectedImage.size.height))]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["button": button]));

button.addTarget(self, action: #selector(centerButtonAction(_:)), for: .touchUpInside)
centerButton = button
updateCenterButton()
}
Expand All @@ -161,19 +161,19 @@ class HELargeCenterTabBarController: UITabBarController {

- parameter sender: The sender of the action.
*/
@IBAction dynamic private func centerButtonAction(sender: AnyObject) {
@IBAction dynamic fileprivate func centerButtonAction(_ sender: AnyObject) {
if allowSwitch {
selectedViewController = centerViewController
}

if let buttonTarget = buttonTarget, buttonAction = buttonAction {
buttonTarget.performSelector(buttonAction, withObject: sender)
if let buttonTarget = buttonTarget, let buttonAction = buttonAction {
let _ = buttonTarget.perform(buttonAction, with: sender)
}
}


/// Obtains the center UIViewController, if any.
public var centerViewController: UIViewController? {
open var centerViewController: UIViewController? {
if let viewControllers = viewControllers {
let centerVC = viewControllers[viewControllers.count / 2]
return centerVC
Expand All @@ -185,14 +185,14 @@ class HELargeCenterTabBarController: UITabBarController {
/**
Ensures the center button cosmetics are correct, regarding the button images.
*/
private func updateCenterButton() {
fileprivate func updateCenterButton() {
var buttonImage = buttonImageUnselected
if selectedViewController === centerViewController {
buttonImage = buttonImageSelected
}

if let centerButton = centerButton {
centerButton.setBackgroundImage(buttonImage, forState: .Normal)
centerButton.setBackgroundImage(buttonImage, for: UIControlState())
}
}

Expand All @@ -203,7 +203,7 @@ class HELargeCenterTabBarController: UITabBarController {
private typealias TabBarControllerDelegate = HELargeCenterTabBarController
extension TabBarControllerDelegate: UITabBarControllerDelegate {

public func tabBarController(tabBarController: UITabBarController, didSelectViewController viewController: UIViewController) {
public func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
if tabBarController === self {
if viewController === centerViewController {
if let centerButton = centerButton {
Expand All @@ -217,7 +217,7 @@ extension TabBarControllerDelegate: UITabBarControllerDelegate {
}


public func tabBarController(tabBarController: UITabBarController, shouldSelectViewController viewController: UIViewController) -> Bool {
public func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
var should = true
if centerViewController === viewController && !allowSwitch {
should = false
Expand Down
Loading

0 comments on commit 8af0e32

Please sign in to comment.