Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ tabPageViewController.isInfinity = true

## Requirements

iOS8+
iOS9+

## Installation

Expand Down
90 changes: 17 additions & 73 deletions Sources/TabPageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,43 +137,16 @@ extension TabPageViewController {

fileprivate func configuredTabView() -> TabView {
let tabView = TabView(isInfinity: isInfinity, option: option)
tabView.translatesAutoresizingMaskIntoConstraints = false

let height = NSLayoutConstraint(item: tabView,
attribute: .height,
relatedBy: .equal,
toItem: nil,
attribute: .height,
multiplier: 1.0,
constant: option.tabHeight)
tabView.addConstraint(height)
view.addSubview(tabView)

let top = NSLayoutConstraint(item: tabView,
attribute: .top,
relatedBy: .equal,
toItem: topLayoutGuide,
attribute: .bottom,
multiplier:1.0,
constant: 0.0)

let left = NSLayoutConstraint(item: tabView,
attribute: .leading,
relatedBy: .equal,
toItem: view,
attribute: .leading,
multiplier: 1.0,
constant: 0.0)

let right = NSLayoutConstraint(item: view,
attribute: .trailing,
relatedBy: .equal,
toItem: tabView,
attribute: .trailing,
multiplier: 1.0,
constant: 0.0)

view.addConstraints([top, left, right])
tabView.translatesAutoresizingMaskIntoConstraints = false
tabBarTopConstraint = tabView.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor)
NSLayoutConstraint.activate([
tabView.heightAnchor.constraint(equalToConstant: option.tabHeight),
tabBarTopConstraint!,
tabView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
tabView.trailingAnchor.constraint(equalTo: view.trailingAnchor)
])

tabView.pageTabItems = tabItems.map({ $0.title})
tabView.updateCurrentIndex(beforeIndex, shouldScroll: true)
Expand All @@ -182,52 +155,23 @@ extension TabPageViewController {
self?.displayControllerWithIndex(index, direction: direction, animated: true)
}

tabBarTopConstraint = top

return tabView
}

private func setupStatusView() {
let statusView = UIView()
statusView.backgroundColor = option.tabBackgroundColor
statusView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(statusView)

let top = NSLayoutConstraint(item: statusView,
attribute: .top,
relatedBy: .equal,
toItem: view,
attribute: .top,
multiplier:1.0,
constant: 0.0)

let left = NSLayoutConstraint(item: statusView,
attribute: .leading,
relatedBy: .equal,
toItem: view,
attribute: .leading,
multiplier: 1.0,
constant: 0.0)

let right = NSLayoutConstraint(item: view,
attribute: .trailing,
relatedBy: .equal,
toItem: statusView,
attribute: .trailing,
multiplier: 1.0,
constant: 0.0)

let height = NSLayoutConstraint(item: statusView,
attribute: .height,
relatedBy: .equal,
toItem: nil,
attribute: .height,
multiplier: 1.0,
constant: topLayoutGuide.length)

view.addConstraints([top, left, right, height])

statusViewHeightConstraint = height
statusView.translatesAutoresizingMaskIntoConstraints = false
statusViewHeightConstraint = statusView.heightAnchor.constraint(equalToConstant: topLayoutGuide.length)
NSLayoutConstraint.activate([
statusView.topAnchor.constraint(equalTo: view.topAnchor),
statusView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
statusView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
statusViewHeightConstraint!
])

self.statusView = statusView
}

Expand Down
63 changes: 13 additions & 50 deletions Sources/TabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,40 +47,13 @@ internal class TabView: UIView {
addSubview(contentView)
contentView.backgroundColor = option.tabBackgroundColor.withAlphaComponent(option.tabBarAlpha)

let top = NSLayoutConstraint(item: contentView,
attribute: .top,
relatedBy: .equal,
toItem: self,
attribute: .top,
multiplier: 1.0,
constant: 0.0)

let left = NSLayoutConstraint(item: contentView,
attribute: .leading,
relatedBy: .equal,
toItem: self,
attribute: .leading,
multiplier: 1.0,
constant: 0.0)

let bottom = NSLayoutConstraint (item: self,
attribute: .bottom,
relatedBy: .equal,
toItem: contentView,
attribute: .bottom,
multiplier: 1.0,
constant: 0.0)

let right = NSLayoutConstraint(item: self,
attribute: .trailing,
relatedBy: .equal,
toItem: contentView,
attribute: .trailing,
multiplier: 1.0,
constant: 0.0)

contentView.translatesAutoresizingMaskIntoConstraints = false
self.addConstraints([top, left, bottom, right])
NSLayoutConstraint.activate([
contentView.topAnchor.constraint(equalTo: topAnchor),
contentView.leadingAnchor.constraint(equalTo: leadingAnchor),
contentView.bottomAnchor.constraint(equalTo: bottomAnchor),
contentView.trailingAnchor.constraint(equalTo: trailingAnchor)
])

let bundle = Bundle(for: TabView.self)
let nib = UINib(nibName: TabCollectionCell.cellIdentifier(), bundle: bundle)
Expand All @@ -95,23 +68,13 @@ internal class TabView: UIView {
currentBarView.removeFromSuperview()
collectionView.addSubview(currentBarView)
currentBarView.translatesAutoresizingMaskIntoConstraints = false
let top = NSLayoutConstraint(item: currentBarView,
attribute: .top,
relatedBy: .equal,
toItem: collectionView,
attribute: .top,
multiplier: 1.0,
constant: option.tabHeight - currentBarViewHeightConstraint.constant)

let left = NSLayoutConstraint(item: currentBarView,
attribute: .leading,
relatedBy: .equal,
toItem: collectionView,
attribute: .leading,
multiplier: 1.0,
constant: 0.0)
currentBarViewLeftConstraint = left
collectionView.addConstraints([top, left])
currentBarViewLeftConstraint = currentBarView.leadingAnchor.constraint(equalTo: collectionView.leadingAnchor)
NSLayoutConstraint.activate([
currentBarView.topAnchor.constraint(
equalTo: collectionView.topAnchor,
constant: option.tabHeight - currentBarViewHeightConstraint.constant),
currentBarViewLeftConstraint!
])
}

bottomBarViewHeightConstraint.constant = 1.0 / UIScreen.main.scale
Expand Down
2 changes: 1 addition & 1 deletion TabPageViewController.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/EndouMari/TabPageViewController.git", :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

s.platform = :ios, '8.0'
s.platform = :ios, '9.0'
s.requires_arc = true

s.source_files = 'Sources/*.swift'
Expand Down
12 changes: 6 additions & 6 deletions TabPageViewController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = Demo/TabPageViewControllerDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MTL_ENABLE_DEBUG_INFO = YES;
PRODUCT_BUNDLE_IDENTIFIER = jp.vasily.TabPageViewControllerDemo;
Expand Down Expand Up @@ -464,7 +464,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = Demo/TabPageViewControllerDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MTL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = jp.vasily.TabPageViewControllerDemo;
Expand All @@ -487,7 +487,7 @@
);
HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = TabPageViewController.xcodeproj/TabPageViewController_Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
Expand All @@ -511,7 +511,7 @@
);
HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = TabPageViewController.xcodeproj/TabPageViewController_Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
Expand Down Expand Up @@ -567,7 +567,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_NS_ASSERTIONS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
ONLY_ACTIVE_ARCH = YES;
OTHER_SWIFT_FLAGS = "-DXcode";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -589,7 +589,7 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DYLIB_INSTALL_NAME_BASE = "@rpath";
GCC_OPTIMIZATION_LEVEL = s;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
OTHER_SWIFT_FLAGS = "-DXcode";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
Expand Down