Center Tab Bar Icons Without Text in Swift - swift

we're trying to center the tab bar icons to the tab bar center because we don't want to have the text below. So the icons should be alone and centered in the tab bar. This is how they look now. The tab bar controller is not the root viewcontroller, so we can't access it directly using rootviewcontroller as many responses we've found out there. Any ideas? We're turning crazy...

To remove titletext, you can use code:
let tabBarItems = tabBar.items! as [UITabBarItem]
tabBarItems[0].title = nil
To get center of icon tabs, use this code
let tabBarItems = tabBar.items! as [UITabBarItem]
tabBarItems[0].imageInsets = UIEdgeInsetsMake(6,0,-6,0)
for complete code remove titletext and get center icon
let tabBarItems = tabBar.items! as [UITabBarItem]
tabBarItems[0].title = nil
tabBarItems[0].imageInsets = UIEdgeInsetsMake(6,0,-6,0)

Related

Is there a way to move a SwiftUI view contained within a UIHostingController into the NavBar Space

My current implementation appends the UIHostingController below the NavBar. But I want the UIhostingController to begin at the end of the status bar (the gray area below the notch). Here is the code and resulting image:
self.reviewHomePage = ReviewHomePage(reviewDict: reviewDict)
let hostingController = UIHostingController(rootView: self.reviewHomePage)
self.addChild(hostingController)
hostingController.view.frame = self.view.frame
view.addSubview(hostingController.view)
hostingController.didMove(toParent: self)
I have tried to hide the NavBar using the various techniques discussed here: Storyboard - Hiding top bar of navigation controller programmatically. But after hiding the NavBar, the space the NavBar occupies is still reserved for the NavBar (the background color is just changed to gray). I have tried to adjust the frame to start within the navBar space with the following code:
let navHeight = self.navigationController!.navigationBar.frame.minY
let topFullView = ((self.navigationController?.view.frame.minY)!) + (navHeight)
let reviewFrame = CGRect(x: (self.navigationController?.view.frame.minX)!,
y: (topFullView),
width: self.navigationController!.view.frame.width,
height: self.navigationController!.view.frame.height - topFullView)
But the UIHostingController is moved up behind the NavBar as shown in the image below.
Is it possible to completely remove the NavBar or append the view on top of the NavBar while maintaining the TabBar at the bottom of the screen? I appreciate the help!

Erase borders between navigation bar and searchBar swift 4

I am setting both the navigation bar and the search bar to a custom UIColor (which I call categoryColor in my code). When I do that, I still see an upper grayish line between nav bar and search bar. I have already set the searchBar border color to be the same as the others, but that gray line still exists. Does anyone know how to get rid of it?
Here is my code:
override func viewWillAppear(_ animated: Bool) {
//defining the color that will be used for all the items
let categoryColor = UIColor(hexString: selectCategory?.categoryColorHex ?? UIColor.randomFlat.hexValue())
//changing navigation bar tint color
navigationController?.navigationBar.barTintColor = categoryColor
//changing searchbar tint color
searchBar.barTintColor = categoryColor
//change searchBar border's color
searchBar.layer.borderColor = categoryColor?.cgColor
searchBar.layer.borderWidth = 3
//changing title that appears at the top, after list is loaded
title = selectCategory?.listName ?? "Todoey"
}
Here is a picture of what I see when I run the simulation:
The better way for implementing search bar with nav controller would be to use searchController inside a navigationController so the searchController will have the same background as navigationController. Here’s a great tutorial about that: https://m.youtube.com/watch?v=h7caxpp3Xps
Edit:
Also if you already implemented search capabilities you can do that with searchController too. Just set navigationController.searchConroller.searchBar.delegate for class that’s responsible for handling delegate methods

UITabBarController customisation page top bar colour swift

How do I change the colour of the top bar of the customisation page of the more view controller. Please see the linked image. Sorry I can't post image here because of my low reputation.
Screenshot Image
Edited with more info:
I have managed to change the background color using the following code. But cant change the color of the top bar.
func tabBarController(tabBarController: UITabBarController, willBeginCustomizingViewControllers viewControllers: [AnyObject]) {
var editView : UIView = tabBarController.view.subviews[1] as! UIView
editView.backgroundColor = UIColor.blackColor()
}
Basically 2 Ways you can achieve this if you are using Global Unique colour in the app for All navigation bar
Use this Solution on App Launch:
UINavigationBar.appearance().barTintColor = UIColor.redColor()
Or if you want to change the Color of More navigationcontroller only then
Use this Solution by getting the Tabbar Reference :
self.tabBarController?.moreNavigationController.navigationBar.barTintColor = UIColor.greenColor()
You can use second solution in the First viewcontroller of the Tab, because that contains your tabbar reference

Change tintColor of Tab Bar in UIView via Storyboard or Swift?

I've found a post on how to change the tint color of the tab bar button, but it assumes you are using a tab bar controller. I tried any way and did not make a difference. I am using a regular UIView and dragged a Tab Bar control on there. How do I change the button tint color in this scenario? The storyboard and code suggestions are not making a change. I tried to add these into my viewDidLoad ever, but neither had an effect:
self.view.tintColor = UIColor.orangeColor()
self.tabBarController?.tabBar.tintColor = UIColor.orangeColor()
I was able to change the nav bar buttons tints via the storyboard no problem, but the tab bar isn't having any effect. I am trying to match the changes I did to the nav bar:
If you are using a Tab Bar Controller, this will work for the tab bar background color:
tabBarController?.tabBar.barTintColor = UIColor.whiteColor()
And this for the color of the items within the tab bar:
tabBarController?.tabBar.tintColor = UIColor.blackColor()
If you are not using a Tab Bar Controller, and you just dragged a tab bar into your view controller: Control drag from the tab bar in your storyboard to your view controller's swift file to create a new referencing outlet. It should something like this if you're unfamiliar:
#IBOutlet weak var myTabBar: UITabBar!
Then use that same lines of code above just replacing a few things:
myTabBar.barTintColor = UIColor.whiteColor()
myTabBar.tintColor = UIColor.blackColor()

Tab Bar - custom images without titles

I want to set my tab bar to have custom images but XCode insists in leaving the space for the tab bar item title text leaving my images positioned too high in the tab bar. I've tried the following code in my TabBarController.swift viewDidLoad function:
let tabItems = tabBar.items as [UITabBarItem]
tabItems[0].title = nil
tabItems[0].selectedImage = UIImage(named: "HomeWhiteIcon")
tabItems[1].title = "Database"
tabItems[1].selectedImage = UIImage(named: "Second")
tabItems[2].title = nil
tabItems[2].selectedImage = UIImage(named: "SettingsWhiteIcon")
tabItems[3].title = nil
tabItems[3].selectedImage = UIImage(named: "ReportsWhiteIcon")
However, although no title is displayed the images are positioned too high as pic below (please ignore database icon - I have not set this icon yet.
Here's a random stab as swift is not my strong suit, but perhaps the database icon having a title is causing the entire title row to not collapse. Try removing the title from the database icon.
Otherwise have you seen the setTitlePositionAdjustment method? Perhaps adjust the title's position up into the icon and the space below will go away.