Tab Bar icons are not conforming to image insets - ios

I am trying to get the icons in the tab bar to be brought down more into the middle of the bar. I have tried setting the image insets in the story board as well as through code and none of it is working.
I'm currently using iOS 15 + Xcode 13.1.
EX: (top: 6, right: 0, bottom: -6, left: 0)
This is an example of the code I attempted as well:
tabBar.items?[0].imageInsets = UIEdgeInsets(top: 6, left: 20, bottom: -6, right: 0)
This is a picture of the current state. You'll see that even without a title, all the icons float to the top of the bar and I want them to be aligned lower in the bar.

I am not 100% sure but as far as I know there is no way to change it's alignment.

I would not recommend modifying the native tab bar. If you definitely want to update the position of tab bar items I encourage you to use a custom tab bar. You will have a lot more control over how it behaves and you will avoid any hacky solution.

Related

Styling the navigation bar with the same visual effect as the tab bar

I'm attempting to make my navigation bar have the exact same style as the tab bar. While it's easy enough to set the navigation bar to be translucent. It's no where near the same "frosty glass" translucency effect that the tab bar has. From just glancing, it would appear that the tab bar implements some sort of light gray color with more transparency.
I've attached an image that shows the closest I was able to get. Does anyone have any ideas on how to accomplish this?
I think it would be better to design a png image like that with photoshop and then set that image as a background to the navigation var with the following code.
UINavigationBar.appearance().setBackgroundImage(UIImage(named: "image")!.resizableImage(withCapInsets: UIEdgeInsetsMake(0, 0, 0, 0), resizingMode: .stretch), for: .default)

Make status bar not be translucent (React Native)

I'm creating an app in React Native that uses react-navigation.
I have some views that animate off the screen towards the top of the screen. While animating, the view goes behind the react-navigation navigation header. It goes behind the iOS status bar, but the status bar is translucent, so it shows the status bar text on top of the view. The status bar is no longer white, but the color of the view under it.
This doesn't look right and I would like the status bar to be always on top and not translucent. What is the best way to go about this?
I was finally able to avoid content overlapping the status bar by placing this element in my topmost container:
<View
style = {{
height: 20,
width: width,
backgroundColor: 'white',
zIndex: 3,
position: 'absolute',
top: 0,
left: 0,
}}
/>
The status bar still shows but animated content never overlaps it.
It's because your react-navigation header has a elevation property, that works strangely (i think just in some cases) as a zIndex in Android, you probably can fix this by adding a higher zIndex to your iOS status bar than you have in the animation.
EDIT: Solved in How to set iOS status bar background color

How to change navigationBar height in iOS 11?

Apparently changing the navigationBar height faced a new approach in iOS 11.
in previous iOS versions it was possible to change the navigationBar height by hiding the default navigationBar and adding a new one with custom frame:
self.navigationController?.setNavigationBarHidden(true, animated: false)
let customNavigationBar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: self.view.bounds.width, height: 64))
self.view.addSubview(customNavigationBar)
But it seems that it is not working in iOS 11 xCode beta. no matter what the new height is, it will always stay at 44.
this is what I've got in xCode 9:
does anyone know how to solve the problem?
Your code is working fine and it´s nothing wrong with it. If you change the background color of your customNavigationBar you´ll see that you´ll get the navigation bar with the desired height. But it seems like it´s an issue with Xcode 9 to hide the default navigation bar.
Your code with:
Xcode 9
Xcode 8
As you can see in the Xcode 9 image, you have the custom navigation bar but the default one does not hide. Probably a bug in Xcode 9, I did not manage to hide it through the Storyboard either.
This seems to be a bug in Xcode 9, bug reports has been filed to Apple.
This is more of a hack till Apple fixes the bug. I was facing the same issue, so I changed the top constraint of the navigation bar from 0 to 20.
Before:
After:
In case your UINavigationBar backgroundColor is something other than white, this will leave the status bar with a white color. You can fix this by adding the following in that particular UIViewController.
let statusBarView = UIView(frame: UIApplication.shared.statusBarFrame)
let statusBarColor = UIColor.red
statusBarView.backgroundColor = statusBarColor
view.addSubview(statusBarView)
Before:
After:
This seems like a lengthy hack, but still better than going back and compiling using Xcode 8.3.
The only way I could make it work was to delete the current custom Navigation Bar, and apply an embed UINavigationController to the UIViewController.
Editor -> Embed In -> Navigation Controller.
On the new created Navigation Controller properties, on the Utilities (right side bar) menu 'Simulated Metrics' the 'Top Bar' attribute must be specified. In my case I needed the value: 'Opaque Navigation Bar'.
I also set the same value of 'Top Bar' on my UIViewController, just to make sure.
By doing that, a new 'Navigation Item' will be at your disposal, and you can re-add your Bar Button Items.
It's the best I could do while we wait for the Xcode 9 update to fix it.
In iOS 11 we cannot change the navigation bar height, If you want to increase the height we should go with custom view.
Reference:
https://forums.developer.apple.com/thread/88202
Still haven't found how to change it size in pixels. But this is possible to create double navigation bar size (XCode 10.1):
self.navigationController?.navigationBar.prefersLargeTitles = true
Result:
This answer did the job for me.
navigationController.navigationBar.setTitleVerticalPositionAdjustment(CGFloat(10),
forBarMetrics: UIBarMetrics.Default)

Is it possible to draw over the status bar in react native?

I am working on a "drawer menu" component. The menu is an overlay that comes form the side and partially covers the main screen.
Is it possible to make it partially cover the status bar too? I have seen this effect in Google Inbox.
Yes, it is possible to make it partially cover the status bar. You can create a view component and you can position it with an absolute position. Based on this library, you can add this style to a view component
{
right: 0,
left: 0,
top: 0,
bottom: 0,
position: 'absolute',
backgroundColor: 'transparent'
}
Then you can add a custom width to the same view so the drawer doesn't take all the screen width.
You can also use the react-native DrawerLayoutAndroid, but this component is only available on android.

iOS Tab Bar icons keep getting larger

I am having a problem with my icons in my tabBar.
Tapping the same tab bar button repeatedly will keep increasing the tab bar icon's size.
If I push a different one, it goes back to its original size.
Any ideas what I should fix?
As per the project shared by the OP (see question comments), it seems the tab bar image insets seem to be messing things up.
Steps to resolve the issue:
Select the tab bar item of the problematic ViewControllers in IB
Go to Size Inspector section (on the right)
Ensure your image insets are balanced
If you give 5px inset to top then balance with a -5px inset to bottom
If you give 5px inset to left then balance with a -5px inset to right
I have no explanation for this, sorry... but if anyone does then kindly comment/post
try This..
myDealNavigationController.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
I was also running with same issue and above accepted answer helped me.
Just to show case what steps to do:
While setting image to tab bar select image and balance image insets from all sides.
Need to keep few things in mind:
As shown in below image, balance from all four sides.
It will make UI proper.
Thanks

Resources