IOS custom UITabBar

Source: Internet
Author: User

You can use hidesBottomBarWhenPushed to hide a page.

Step 1: We need some images:


The icons of each option and the background image of tabbar are also a transparent 1x1 pixel image.

Step 2: Create a project and create a class in the project that inherits from UITabBarController.


Step 3: first write a method and return a UINavigationController

-(UINavigationController*) viewControllerWithTitle:(NSString*) title image:(UIImage*)image{    UIViewController* viewController = [[UIViewController alloc] init];    viewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:image tag:0];    viewController.title = title;    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:viewController];    return nav;}

Then, create viewControllers of TabbarController in viewDidLoad.

 self.viewControllers = [NSArray arrayWithObjects:                            [self viewControllerWithTitle:@"1" image:IMG(@"1")],                            [self viewControllerWithTitle:@"2" image:IMG(@"2")],                            [self viewControllerWithTitle:nil image:nil],                            [self viewControllerWithTitle:@"3" image:IMG(@"3")],                            [self viewControllerWithTitle:@"4" image:IMG(@"4")], nil];

No. The third ViewController is not set.

Because we need to put a button at that position and continue to write in viewDidLoad:

    UIButton* button = [[UIButton alloc]initWithFrame:CGRectMake(0.0, 0.0, 65, 65)];    button.center = CGPointMake(160, 20);    [button setBackgroundImage:IMG(@"add") forState:UIControlStateNormal];    [button addTarget:self action:@selector(add:) forControlEvents:UIControlEventTouchUpInside];    [self.tabBar addSubview:button];

Then set the background image:

    [self.tabBar setBackgroundImage:IMG(@"tabbarbg")];

After running:



You will find that there is a horizontal line on the button, and then set this shadow to run, no one will find you wretched behavior.

    [self.tabBar setShadowImage:IMG(@"transparent")];
Finally (iOS7 and iOS6 ):


Download



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.