Tabbaritem image inset property changes inset value continueously when item is clicked - ios

I have set the image inset property from custom tabbarController:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
for tabBarItem in tabBar.items!
{
tabBarItem.imageInsets = UIEdgeInsetsMake(-2, 0, 0, 0)
}
}
it's fine when i run the app and click tabbar item first time, looks like
problem arrises when i click the same tabbaritem multiple time it continueously add that inset
when i didn't add any image insets property the tabbar is working properly.
Thanks in advance

Related

Tab bar item icons are sizing very weird

So I don't know how this is happening at all. Ive tried everything remotely related to what might be happening, with no success. I have an initial view controller that presents a tab bar controller onto the screen. And any way I set the icons, which are all the same sizes 1* 2* and 3* wise, the right bar button is abnormally bigger than the other two!?
Heres what it looks like:
class SceneScrollViewController: UITabBarController, UIScrollViewDelegate, UITabBarControllerDelegate {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
delegate = self
let exploreVC = Storyboard.explore.instantiateInitialViewController() as? UINavigationController
let profileVC = Storyboard.profile.instantiateInitialViewController() as? UINavigationController
let hubVC = Storyboard.hub.instantiateInitialViewController() as? UINavigationController
profileVC.tabBarItem.image = UIImage.init(named: "profile")
hubVC.tabBarItem.image = UIImage.init(named: "homeIcon")
exploreVC.tabBarItem.image = UIImage.init(named: "tabBarSearch")
viewControllers = [exploreVC, hubVC, profileVC]
self.selectedIndex = 1
}
}
If you have any idea what is happening please post them, anything helps. Also, the images are all proper size, and what's weirder: if I swap the search icon with profile ie, that same right buttonItem enlarges the search icon, and the profile icon sizes to the current search icon size below. SO no matter what image I set in right button slot, it sizes it weird.
Double-check your icon size, if still showing a larger icon then try to add insets to the tabBarItem.
profileVC.tabBarItem.imageInsets = UIEdgeInsets(top: -4, left: -4, bottom: -4, right: -4)
to make the size of all tabbar icons consistent you can give imageInsets to all tabs.

TableView shows under tabbar

I've got a UITableViewController embedded inside a Navigation and TabBar controller. When I set the background image using
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
let backgroundImage = UIImage(named: "Background.png")
let imageView = UIImageView(image: backgroundImage)
self.tableView.backgroundView = imageView
}
the table appears under the TabBar that is translucent.
I can't use Insets or anything as the code above just sets background to the tableview.
I need something that sets background to the view and not the table to use Insets.
And the problem can be solve by using UIViewController(with tableView inside it) but I gotta use static cells so that is out of scope.

Move tableview below top tab bar

I want to move my table view below tabbar. Presently first row of the tableview is getting hidden behind the tab bar.
I tried
override func viewDidAppear(animated: Bool)
{
self.tableView.frame.origin.y = 50
print("done")
}
I tried the same in viewDidLoad and viewWilAppear
Kindly help me with this
Screen Shot of TabBar with TablView
Try putting this in your ViewDidLoad()method in your view controller. It will move the TableViewController to begin after the navigation bar. However, you will also need to subtract the status bar that is above your navigation bar so I have also added that for you.
self.tableView.contentInset = UIEdgeInsetsMake(-self.navigationController!.navigationBar.frame.size.height - 20, 0, 0, 0)
Cheers.

Table view under navigation bar after tab change

I have an app with two tabs, each one containing a table view. The whole is wrapped in a UINavigationController. Here is my storyboard:
When I run my app, the first tab is OK:
But on the second one, the table view starts under the navigation bar:
Even worse, when I rotate the screen from the second tab, the second tab is now OK, but the first isn't any more, the table view has an extra margin top:
If I rotate back to portrait from the first tab, I return to the initial state (first tab OK, second tab with table view starting under the navigation bar). In fact, each time I rotate the screen, the displayed tab is OK after the rotation, but the other one isn't.
It seems that I need to do something when my views are shown after a tab change, and that thing seems to be done when the screen rotates, but what is it??
EDIT: I forgot to mention that I don't want to uncheck the "Extend Edges: Under Top/Bottom Bars" checkboxes, because I want my table views to scroll under the nav and tab bars.
OK, I got it: first uncheck "Adjust Scroll View Insets" on the UITabBarController, and then add this code on each UITableViewController:
override func viewWillAppear(animated: Bool) {
// Call super:
super.viewWillAppear(animated);
// Update the table view insets:
updateTableViewInsets();
}
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
// Animate:
coordinator.animateAlongsideTransition({ (UIViewControllerTransitionCoordinatorContext) -> Void in
// Update the table view insets:
self.updateTableViewInsets();
}, completion: { (UIViewControllerTransitionCoordinatorContext) -> Void in })
// Call super:
super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
}
private func updateTableViewInsets() {
// Get the bars height:
let navigationBarHeight = self.navigationController!.navigationBar.frame.size.height;
let statusBarHeight = UIApplication.sharedApplication().statusBarFrame.size.height;
let tabBarHeight = self.tabBarController!.tabBar.frame.size.height;
// Create the insets:
let insets: UIEdgeInsets = UIEdgeInsetsMake(navigationBarHeight + statusBarHeight, 0, tabBarHeight, 0);
// Update the insets:
self.tableView.scrollIndicatorInsets = insets;
self.tableView.contentInset = insets;
}
Now I'm handling the insets myself, and everything is smooth. That should work out of the box IMHO, though...
EDIT: It works out of the box with iOS 9, Apple have probably fixed the bug. The code above works with iOS 8 & 9 (and maybe lower, I didn't try).

Start View Controller and remove Tap bar. SWIFT

I'm developing a swift application. I need when I click in a item inside a table it will open a new view. That's fine and working, but te bottom buttons of the tab bar still there. How can I do to this disappear?
Code used to call the next screen. I've tested some different ways but this was the only one that worked fine.. I think this is not the problem in here..
func irParaMarcacoes(nome:String){
let next:ViewMarcacaoController = storyboard?.instantiateViewControllerWithIdentifier("ViewMarcacaoController") as! ViewMarcacaoController
next.projNome = nome;
self.navigationController?.pushViewController(next, animated: true)
}
This is what I have, the first screen
This is what I want the tap bar to disappear
Thanks for yout attention.
*Using XCode 7.3
you can hide navigation bar.
write this code in ViewMarcacaoController
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBarHidden = true
}
You are pushing view controller from navigation bar
so your controller you are pushing is the top view controller of it
so in view will appear method
self.navigationController!.setNavigationBarHidden(true, animated: animated)
to hide bottom bar
self.tabBarController?.tabBar.hidden = true
I found a great solution provided by Michael Campsall in here.
the solution consist basically on:
func setTabBarVisible(visible:Bool, animated:Bool) {
//* This cannot be called before viewDidLayoutSubviews(), because the frame is not set before this time
// bail if the current state matches the desired state
if (tabBarIsVisible() == visible) { return }
// get a frame calculation ready
let frame = self.tabBarController?.tabBar.frame
let height = frame?.size.height
let offsetY = (visible ? -height! : height)
// zero duration means no animation
let duration:NSTimeInterval = (animated ? 0.3 : 0.0)
// animate the tabBar
if frame != nil {
UIView.animateWithDuration(duration) {
self.tabBarController?.tabBar.frame = CGRectOffset(frame!, 0, offsetY!)
return
}
}
}
func tabBarIsVisible() ->Bool {
return self.tabBarController?.tabBar.frame.origin.y < CGRectGetMaxY(self.view.frame)
}
Enable the Hide Bottom bar on Push on your second screen View controller in storyboard as shown in following :
So when you push your viewcontroller, it will hide the bottom Tab bar. When you come back to firstViewController, then tab bar will be shown. No need to write code for this.
Hope it helps..

Resources