Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6186391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:52:54+00:00 2026-05-24T01:52:54+00:00

I have a UIViewController and I wish to place a simple UITabBar like the

  • 0

I have a UIViewController and I wish to place a simple UITabBar like the in the screenshot below: I don’t want to use an UITabBarController. In fact, my original setup uses one, and it’s easy as cake to get it to work.

However, the thing is I found out it’s a bad idea to put UITabBarControllers inside Navigation Controllers, so I’m forced to refactor the hierarchy (so please don’t suggest using one).

Given an UIViewController, how can I add an UITabBar on the bottom programatically? I got my UITabBarDelegate all setup to show a specific view when 1 of the tab bars is clicked, but the problem is when the view controller loads, no tab bar shows up! Here’s my code to do that:

- (void) viewDidLoad {
        ...some initialization...
    CGRect frame = CGRectMake(0, 431, 320, 49);


    profileItem = [[UITabBarItem alloc] init];
    profileItem.image = icon;
    profileItem.title = @"Diet";    

    tabBar = [[UITabBar alloc] initWithFrame:frame];
    NSArray* items = [[NSArray alloc] initWithObjects:profileItem, nil];

    tabBar.items = items;
    tabBar.delegate = self;
    [tabBar setSelectedItem:[tabBar.items objectAtIndex:0]];

    [self.view addSubview:tabBar];
    [super viewDidLoad];
}

What am I missing here?

enter image description here

EDIT: Argh, I found out it has to do with the frame… Hmm.. what y-coordinate should I use if I have an existing navigation header on top?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:52:55+00:00Added an answer on May 24, 2026 at 1:52 am

    You mention in your edit that you already determined that it has to do with the frame. Your problem may stem from the fact that your view’s size in viewDidLoad isn’t guaranteed to be the same is it will be when it eventually gets displayed. UIKit resizes the view to fit the context in which it’s being displayed just before viewWillAppear:.

    If you want to add the tab bar in viewDidLoad, then you should position it at the bottom of your view’s frame by doing some math:

    CGRect frame = CGRectMake(0, self.view.bounds.size.height - 49,
                              self.view.bounds.size.width, 49);
    

    Then set an appropriate autoresizingMask so that it remains at the bottom even if UIKit resizes your view:

    tabBar.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIViewController with its own .xib, and I want to use a
I have subclassed UIViewController into a new class, PageViewController (I'm writing a simple book
I have a UIViewController (which sits inside a tabUIController). Within this UIViewController, I want
I have a UIViewController class and a second which I want to push modally
I have a simple UIViewController in a UITabViewController . The am looking to have
I have a UIViewController that I want to display a second UIViewController as a
I have a UIViewController that I want to add on top of the entire
I have 30 UILabels I wish to use as IBOutlets. However when I try
I have a UIViewController inside of a navigation based app. I'd like the view
I have an UIViewController into an navigationController.All I want is when I rotate from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.