Skip to content

Commit d19452d

Browse files
committed
Updated code base to add the HHTabBarView at top position as well.
1 parent 049e4bd commit d19452d

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

HHTabBarView/HHTabBarView/AppDelegate.swift

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
106106
t5.imageToTitleSpacing = spacing
107107
t5.imageVerticalAlignment = .top
108108
t5.imageHorizontalAlignment = .center
109+
110+
//Set HHTabBarView position.
111+
self.hhTabBarView.tabBarViewPosition = .top
112+
113+
//Set this value according to your UI requirements.
114+
self.hhTabBarView.tabBarViewTopPositionValue = 84.0
109115

110116
//Set Default Index for HHTabBarView.
111117
self.hhTabBarView.tabBarTabs = [t1, t2, t3, t4, t5]
@@ -158,25 +164,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
158164
/////End ------ SETUP HHTabBarView ------
159165

160166

161-
func applicationWillResignActive(_ application: UIApplication) {
162-
// 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.
163-
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
164-
}
165-
166-
func applicationDidEnterBackground(_ application: UIApplication) {
167-
// 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.
168-
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
169-
}
170-
171-
func applicationWillEnterForeground(_ application: UIApplication) {
172-
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
173-
}
174-
175-
func applicationDidBecomeActive(_ application: UIApplication) {
176-
// 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.
177-
}
178-
179-
func applicationWillTerminate(_ application: UIApplication) {
180-
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
181-
}
167+
func applicationWillResignActive(_ application: UIApplication) { }
168+
func applicationDidEnterBackground(_ application: UIApplication) { }
169+
func applicationWillEnterForeground(_ application: UIApplication) { }
170+
func applicationDidBecomeActive(_ application: UIApplication) { }
171+
func applicationWillTerminate(_ application: UIApplication) { }
182172
}

HHTabBarView/HHTabBarView/Source/HHTabBarView.swift

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public enum HHTabBarTabChangeAnimationType {
1515
case flash, shake, pulsate, none
1616
}
1717

18+
///Position Types for HHTabBarView.
19+
public enum HHTabBarViewPosition {
20+
case top, bottom
21+
}
22+
1823
///Easily configured HHTabBarView class to replace the iOS default UITabBarController.
1924
public class HHTabBarView: UIView {
2025

@@ -25,8 +30,14 @@ public class HHTabBarView: UIView {
2530
private(set) public var referenceUITabBarController = UITabBarController()
2631

2732
//MARK: Setters
28-
///Animation Type
33+
///Animation Type. Default: none.
2934
public var tabChangeAnimationType: HHTabBarTabChangeAnimationType = .none
35+
36+
///TabBarView Position. Default: bottom. Also, don't forget to set 'tabBarViewTopPositionValue' if tabBarViewPosition = 'top'.
37+
public var tabBarViewPosition: HHTabBarViewPosition = .bottom
38+
39+
/// If tabBarViewPosition = top then you should set it according to your UI requirements.
40+
public var tabBarViewTopPositionValue: CGFloat = 64.0
3041

3142
///Set HHTabButton for HHTabBarView.
3243
public var tabBarTabs = Array<HHTabButton>() {
@@ -110,11 +121,14 @@ public class HHTabBarView: UIView {
110121
let screentHeight = screenSize.height
111122
let screentWidth = screenSize.width
112123
var tabBarHeight = hhTabBarViewHeight
113-
114-
//To support UI for iPhone X
115-
if #available(iOS 11.0, *) {
116-
let bottomPadding = self.referenceUITabBarController.tabBar.safeAreaInsets.bottom
117-
tabBarHeight += bottomPadding
124+
125+
if self.tabBarViewPosition == .top {
126+
return CGRect.init(x: 0.0, y: self.tabBarViewTopPositionValue, width: screentWidth, height: tabBarHeight)
127+
} else {
128+
if #available(iOS 11.0, *) {
129+
let bottomPadding = self.referenceUITabBarController.tabBar.safeAreaInsets.bottom
130+
tabBarHeight += bottomPadding
131+
}
118132
}
119133

120134
return CGRect.init(x: 0.0, y: (screentHeight - tabBarHeight), width: screentWidth, height: tabBarHeight)

0 commit comments

Comments
 (0)