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

Fixing issue where center button constraints could become disabled #17

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions HELargeCenterTabBarController.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ Pod::Spec.new do |spec|
spec.author = { 'John C. Daub (@hsoi)' => '[email protected]' }
spec.social_media_url = 'https://twitter.com/hsoienterprises'
spec.description = <<-DESC
HELargeCenterTabBarController is a 100% Swift implementation of a UITabBarController with a lager center tab.
HELargeCenterTabBarController is a 100% Swift implementation of a UITabBarController with a lager center tab.
The center tab can be used in the typical manner where a tap switches to display the associated ViewController, or the center tab can be used in an alternate manner where the tap does not switch ViewControllers but instead executes a target-action.

Simple. Lightweight. To-the-point.
DESC
spec.requires_arc = true
spec.license = { :type => 'BSD 3-clause “New” or “Revised”', :file => 'LICENSE' }
spec.source_files = ['HELargeCenterTabBarController/*.swift', 'HELargeCenterTabBarController/*.h']
spec.platform = :ios, '8.0'
spec.platform = :ios, '9.0'
spec.module_name = 'HELargeCenterTabBarController'
end
4 changes: 2 additions & 2 deletions HELargeCenterTabBarController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
RUN_CLANG_STATIC_ANALYZER = YES;
Expand Down Expand Up @@ -430,7 +430,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
RUN_CLANG_STATIC_ANALYZER = YES;
SDKROOT = iphoneos;
Expand Down
22 changes: 11 additions & 11 deletions HELargeCenterTabBarController/HELargeCenterTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,20 @@ class HELargeCenterTabBarController: UITabBarController {
let button = UIButton(type: .custom)
button.translatesAutoresizingMaskIntoConstraints = false
tabBar.addSubview(button)


let bottomAnchor: NSLayoutYAxisAnchor
if #available(iOS 11.0, *) {
NSLayoutConstraint.activate([
button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
button.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
button.widthAnchor.constraint(equalToConstant: unselectedImage.size.width),
button.heightAnchor.constraint(equalToConstant: unselectedImage.size.height)
])
bottomAnchor = tabBar.safeAreaLayoutGuide.bottomAnchor
} else {
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]))
bottomAnchor = tabBar.bottomAnchor
}

NSLayoutConstraint.activate([
button.centerXAnchor.constraint(equalTo: tabBar.centerXAnchor),
button.bottomAnchor.constraint(equalTo: bottomAnchor),
button.widthAnchor.constraint(equalToConstant: unselectedImage.size.width),
button.heightAnchor.constraint(equalToConstant: unselectedImage.size.height)
])

button.addTarget(self, action: #selector(centerButtonAction(_:)), for: .touchUpInside)
centerButton = button
Expand Down