Skip to content

Commit f3a2e60

Browse files
committed
Updated for iPhoneX
Code Refactoring and iPhoneX height improvements.
1 parent dbea829 commit f3a2e60

File tree

4 files changed

+32
-24
lines changed

4 files changed

+32
-24
lines changed

.DS_Store

0 Bytes
Binary file not shown.

HHTabBarView.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.name = 'HHTabBarView'
33
s.module_name = 'HHTabBarView'
4-
s.version = '1.1.0'
4+
s.version = '1.1.1'
55
s.summary = 'A lightweight customized tabbar view. 📌'
66
s.description = 'HHTabBarView is an easy to setup and use replacement of default tabbar.'
77
s.homepage = 'https://github.com/hemangshah/HHTabBarView'

HHTabBarView/HHTabBarView/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>APPL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.1.0</string>
18+
<string>1.1.1</string>
1919
<key>CFBundleVersion</key>
2020
<string>1</string>
2121
<key>LSRequiresIPhoneOS</key>

HHTabBarView/HHTabBarView/Source/HHTabBarView.swift

+30-22
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import UIKit
1010

11-
internal let HHTabBarViewHeight = CGFloat(49.0)
11+
fileprivate let hhTabBarViewHeight = CGFloat(49.0)
1212

1313
///Animation Types for Tab Changes.
1414
public enum HHTabBarTabChangeAnimationType {
@@ -22,7 +22,7 @@ public class HHTabBarView: UIView {
2222
public static var shared = HHTabBarView.init()
2323

2424
///For Internal Navigation
25-
public var referenceUITabBarController = UITabBarController.init()
25+
private(set) public var referenceUITabBarController = UITabBarController.init()
2626

2727
//MARK: Setters
2828
///Animation Type
@@ -31,15 +31,15 @@ public class HHTabBarView: UIView {
3131
///Set HHTabButton for HHTabBarView.
3232
public var tabBarTabs = Array<HHTabButton>() {
3333
didSet {
34-
createTabs()
34+
self.createTabs()
3535
}
3636
}
3737

3838
///Set the default tab for HHTabBarView.
3939
public var defaultIndex = 0 {
4040
didSet {
41-
if areTabsCreated() {
42-
selectTabAtIndex(withIndex: defaultIndex)
41+
if self.areTabsCreated() {
42+
self.selectTabAtIndex(withIndex: defaultIndex)
4343
}
4444
}
4545
}
@@ -48,13 +48,13 @@ public class HHTabBarView: UIView {
4848
///Specify indexes of tabs to lock. [0, 2, 3]
4949
public var lockTabIndexes = Array<Int>() {
5050
didSet {
51-
lockUnlockTabs()
51+
self.lockUnlockTabs()
5252
}
5353
}
5454

5555
///Update Badge Value for Specific Tab.
5656
public func updateBadge(forTabIndex index: Int, withValue value: Int) -> Void {
57-
if areTabsCreated() {
57+
if self.areTabsCreated() {
5858
let hhTabButton = tabBarTabs[index]
5959
hhTabButton.badgeValue = value
6060
}
@@ -75,28 +75,36 @@ public class HHTabBarView: UIView {
7575

7676
required
7777
convenience public init() {
78-
self.init(frame: CGRect.init(x: 0.0, y: 0.0, width: UIScreen.main.bounds.size.width, height: HHTabBarViewHeight))
78+
self.init(frame: CGRect.init(x: 0.0, y: 0.0, width: UIScreen.main.bounds.size.width, height: hhTabBarViewHeight))
7979
//You can configure it to any background color you want.
8080
self.backgroundColor = .clear
8181
//For Portrait/Landscape.
8282
self.autoresizingMask = [.flexibleWidth, .flexibleBottomMargin, .flexibleLeftMargin, .flexibleRightMargin]
8383
//Adding to UITabBarController's subview.
84-
referenceUITabBarController.view.addSubview(self)
84+
self.referenceUITabBarController.view.addSubview(self)
8585
//This is important otherwise tabBar will be visible if tabChangeAnimationType = .flash
86-
referenceUITabBarController.tabBar.isHidden = true
86+
self.referenceUITabBarController.tabBar.isHidden = true
8787
}
8888

8989
//HHTabBarViewFrame Frame
90-
fileprivate func HHTabBarViewFrame() -> CGRect {
90+
fileprivate func getHHTabBarViewFrame() -> CGRect {
9191
let screenSize = UIScreen.main.bounds.size
9292
let screentHeight = screenSize.height
9393
let screentWidth = screenSize.width
94-
return CGRect.init(x: 0.0, y: (screentHeight - HHTabBarViewHeight), width: screentWidth, height: HHTabBarViewHeight)
94+
var tabBarHeight = hhTabBarViewHeight
95+
96+
//To support UI for iPhone X
97+
if #available(iOS 11.0, *) {
98+
let bottomPadding = self.referenceUITabBarController.tabBar.safeAreaInsets.bottom
99+
tabBarHeight += bottomPadding
100+
}
101+
102+
return CGRect.init(x: 0.0, y: (screentHeight - tabBarHeight), width: screentWidth, height: tabBarHeight)
95103
}
96104

97105
//UI Updates
98106
public override func layoutSubviews() {
99-
self.frame = HHTabBarViewFrame()
107+
self.frame = getHHTabBarViewFrame()
100108
}
101109

102110
//Helper to Select a Particular Tab.
@@ -113,18 +121,18 @@ public class HHTabBarView: UIView {
113121
}
114122

115123
// Apply Tab Changes in UITabBarController
116-
referenceUITabBarController.selectedIndex = tabIndex
124+
self.referenceUITabBarController.selectedIndex = tabIndex
117125

118126
// Lock or Unlock the Tabs if requires.
119-
lockUnlockTabs()
127+
self.lockUnlockTabs()
120128

121129
let currentHHTabButton = tabBarTabs[tabIndex]
122130
currentHHTabButton.isUserInteractionEnabled = false
123131
}
124132

125133
//Check if Tabs are created.
126134
fileprivate func areTabsCreated() -> Bool {
127-
if !tabBarTabs.isEmpty {
135+
if !self.tabBarTabs.isEmpty {
128136
return true
129137
}
130138
return false
@@ -139,8 +147,8 @@ public class HHTabBarView: UIView {
139147
}
140148

141149
//Then Lock the provided Tab Indexes.
142-
if !lockTabIndexes.isEmpty {
143-
for index in lockTabIndexes {
150+
if !self.lockTabIndexes.isEmpty {
151+
for index in self.lockTabIndexes {
144152
let hhTabButton = tabBarTabs [index]
145153
hhTabButton.isUserInteractionEnabled = false
146154
}
@@ -155,7 +163,7 @@ public class HHTabBarView: UIView {
155163

156164
let width = CGFloat(self.frame.size.width)/CGFloat(tabBarTabs.count)
157165
let height = self.frame.size.height
158-
166+
159167
for hhTabButton in tabBarTabs {
160168
hhTabButton.frame = CGRect.init(x: xPos, y: yPos, width: width, height: height)
161169
hhTabButton.addTarget(self, action: #selector(actionTabTapped(tab:)), for: .touchUpInside)
@@ -170,16 +178,16 @@ public class HHTabBarView: UIView {
170178

171179
//Actions
172180
@objc fileprivate func actionTabTapped(tab: HHTabButton) {
173-
if onTabTapped != nil {
174-
animateTabBarButton(tabBarButton: tab)
181+
if self.onTabTapped != nil {
182+
self.animateTabBarButton(tabBarButton: tab)
175183
self.selectTabAtIndex(withIndex: tab.tabIndex)
176184
self.onTabTapped(tab.tabIndex)
177185
}
178186
}
179187

180188
//Perform Animation on Tab Changes.
181189
fileprivate func animateTabBarButton(tabBarButton: HHTabButton) {
182-
switch tabChangeAnimationType {
190+
switch self.tabChangeAnimationType {
183191
case .flash:
184192
tabBarButton.flash()
185193
break

0 commit comments

Comments
 (0)