To customize the Tabbar, click the middle button without toggling the page, but let the current child view controller jump to the new page. (similar to Sina Weibo release)

Source: Internet
Author: User

- (void) viewdidload {[Super viewdidload]; //Do any additional setup after loading the view.Self.Delegate=Self ; /************************ hides the black lines on the Tabbar ***************************/CGRect rect= CGRectMake (0,0, Self.view.frame.size.width, self.view.frame.size.height);    Uigraphicsbeginimagecontext (rect.size); Cgcontextref Context=Uigraphicsgetcurrentcontext ();    Cgcontextsetfillcolorwithcolor (context, [[Uicolor Clearcolor] cgcolor]);    Cgcontextfillrect (context, rect); UIImage*img =Uigraphicsgetimagefromcurrentimagecontext ();    Uigraphicsendimagecontext ();    [Self.tabbar setbackgroundimage:img];    [Self.tabbar setshadowimage:img]; /************************ hides the black lines on the Tabbar ***************************/Uitabbaritem*ITEM1 = [[Uitabbaritem alloc]initwithtitle:@"Home Page"Image:[[uiimage imagenamed:@"Tabbar_home"] Imagewithrenderingmode:uiimagerenderingmodealwaysoriginal] Tag:0]; Item1.selectedimage= [[UIImage imagenamed:@"tabbar_home_selected"] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; Uitabbaritem*ITEM2 = [[Uitabbaritem alloc]initwithtitle:@""Image:[[uiimage imagenamed:@"Tabbar_order"] Imagewithrenderingmode:uiimagerenderingmodealwaysoriginal] Tag:0]; Uitabbaritem*ITEM3 = [[Uitabbaritem alloc]initwithtitle:@"my own"Image:[[uiimage imagenamed:@"Tabbar_person"] Imagewithrenderingmode:uiimagerenderingmodealwaysoriginal] Tag:0]; Item3.selectedimage= [[UIImage imagenamed:@"tabbar_person_selected"] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; Nsarray*controllers = @[@"Homepage",@"Order",@" Person"];  for(inti =0; I <3; i++) {Class cls= Nsclassfromstring ([NSString stringWithFormat:@"% @ViewController", Controllers[i]]); Uiviewcontroller*controller = (Uiviewcontroller *) [[CLS Alloc] init]; Uinavigationcontroller*NC =[[Uinavigationcontroller alloc] initwithrootviewcontroller:controller]; Nc.tabbaritem=@[item1,item2,item3][i];    [Self ADDCHILDVIEWCONTROLLER:NC]; } Uiimageview*tabbarview = [[Uiimageview alloc] Initwithframe:cgrectmake (0, Self.tabBar.frame.size.height- A, Screen_width, A)]; Tabbarview.image= [UIImage imagenamed:@"Tabbar"];    [Self.tabbar Addsubview:tabbarview]; }-(BOOL) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontroller Shouldselectviewcontroller: (UIViewController *) Viewcontroller {if(Viewcontroller = = self.viewcontrollers[1]) {        //Click the middle Tabbaritem, do not switch, let the current page jumpOrderviewcontroller *order =[[Orderviewcontroller alloc] init]; Order.hidesbottombarwhenpushed=YES; [(Uinavigationcontroller*) Tabbarcontroller.selectedviewcontroller Pushviewcontroller:order Animated:yes]; returnNO; }    returnYES;}

To customize the Tabbar, click the middle button without toggling the page, but let the current child view controller jump to the new page. (similar to Sina Weibo release)

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.