1

I have this complete app build programmatically right from beginning. The project was started on an old Xcode may be Xcode 6. I am currently building on Xcode 6. My Project has Objective-C and Swift files communicating with each other. The problem I am having is because it is built programmatically, I cannot just go into the storyboard and set use safe areas layout.

My Tab Bar Images on Xcode 9.2 are going crazy and also the nav bar. I want to fix the images as well as height of the tab bar.

enter image description here

Here is the code in AppDelegate for adding tabbarcontroller.

- (void)setupView {

    UIViewController *firstViewController = [[UIViewController alloc]init];
    firstViewController.view.backgroundColor = UIColor.redColor;
    firstViewController.title = @"First View";
    firstViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemSearch tag:0];
    UINavigationController *firstNavController = [[UINavigationController alloc] initWithRootViewController:firstViewController];

    UIViewController *secondViewController = [[UIViewController alloc]init];
    secondViewController.view.backgroundColor = UIColor.blueColor;
    secondViewController.title = @"Second View";
    secondViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1];
    UINavigationController *secondNavController = [[UINavigationController alloc] initWithRootViewController:secondViewController];

    UIViewController *thirdViewController = [[UIViewController alloc]init];
    thirdViewController.view.backgroundColor = UIColor.purpleColor;
    thirdViewController.title = @"Third View";
    thirdViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemRecents tag:2];
    UINavigationController *thirdNavController = [[UINavigationController alloc]initWithRootViewController:thirdViewController];

    UIViewController *fourthViewController = [[UIViewController alloc]init];
    fourthViewController.view.backgroundColor = UIColor.greenColor;
    fourthViewController.title = @"Fourth View";
    fourthViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemHistory tag:2];
    UINavigationController *fourthNavController = [[UINavigationController alloc]initWithRootViewController:fourthViewController];

    tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
    [tabBarController.tabBar invalidateIntrinsicContentSize];
    tabBarController.viewControllers = [[NSArray alloc] initWithObjects:firstNavController, secondNavController, thirdNavController, fourthNavController, nil];
    tabBarController.delegate = self;
    [tabBarController.view setNeedsLayout];

    self.window.rootViewController = tabBarController;
    [self.window makeKeyAndVisible];
}

I have added the iPhone X Splash screen which made the complete app to go I have researched enough but not able to find a solution.

Swati
  • 1,417
  • 1
  • 15
  • 35

1 Answers1

0

You apparently missed this line [[tabBarController view] setAutoresizingMask:UIViewAutoresizingFlexibleHeight];

tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
[tabBarController.tabBar invalidateIntrinsicContentSize];
tabBarController.viewControllers = [[NSArray alloc] initWithObjects:firstNavController, secondNavController, thirdNavController, fourthNavController, nil];

/* Enter this line */
[[tabBarController view] setAutoresizingMask:UIViewAutoresizingFlexibleHeight];

tabBarController.delegate = self;
[tabBarController.view setNeedsLayout];

I tried with your code and got the result:

Here is a screenshot:

enter image description here

Subhajit Halder
  • 1,427
  • 13
  • 21