ios 11 UITabBar UITabBarItem positioning issue
I am maintaining a large iPad app written mostly in Objective-C that has survived several iOS releases. I ran into the situation where I needed the pre-iOS 11 tab bar appearance (with the icons above the titles instead of next to them) for a couple tab bars. My solution was to create a subclass of UITabBar that overrides the traitCollection
method so that it always returns a horizontally-compact trait collection. This causes iOS 11 to display the titles below the icons for all of the tab bar buttons.
In order to use this, set the custom class of the tab bars in the storyboard to this new subclass and change any outlets in the code that point to the tab bars to be of this new type (don't forget to import the header file below).
The .h file is pretty much empty in this case:
//
// MyTabBar.h
//
#import <UIKit/UIKit.h>
@interface MyTabBar : UITabBar
@end
Here is the .m file with the implementation of the traitCollection
method:
//
// MyTabBar.m
//
#import "MyTabBar.h"
@implementation MyTabBar
// In iOS 11, UITabBarItem's have the title to the right of the icon in horizontally regular environments
// (i.e. the iPad). In order to keep the title below the icon, it was necessary to subclass UITabBar and override
// traitCollection to make it horizontally compact.
- (UITraitCollection *)traitCollection {
return [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact];
}
@end
Is there a way to change the text position in UITabBar or UITabBarItem?
Why don't you just have an empty title property for your view controller and add the title to your custom images for the tab?
UPDATE: For the sake of completeness of answer; from comments and ios tabbar put text in the middle when no image
[tab.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -10)]
Related Topics
Autolayout Complains About Constraints for 2 Uitextfields with No Borders
Maximum Height of iOS 8 Today Extension
Add a Button on Right View of Uitextfield in Such Way That, Text Should Not Overlap the Button
How to Send Post Parameters in Swift
Change Lock Screen Background Audio Controls Text
iPhone - Convert Ctfont to Uifont
Redirect Nslog to File in Swift Not Working
Unexpected Behavior When Casting an Nsnumber to Float
Sort Array of Dictionaries by Key Value
Why Can't I Invert My Image Back to Original with Cifilter in My Swift iOS App
Input Field iOS Safari Bug - Can't Type in Any Text
CSS Styled Scrollbars Support for Safari Mobile on iOS 6 Disappeared
Swift - Apply Local CSS to Web View
Z-Index Issue on iOS Safari & Chrome
How to Limit an iOS App Only to 4 Inch Screen Devices
Launching Viber App via Url Scheme on iOS
How to Display Nested Array Data Inside Uitableview Properly with Multiple Level of Sections