ios-Custom Tabbar

Source: Internet
Author: User

1 //2 //RQHTABBARCONTROLLER.M3 //Tabbarview4 //5 //Created by Apple on 15-1-13.6 //Copyright (c) 2015 __mycompanyname__. All rights reserved.7 //You can have this class associated with storyboard, which inherits Uitabbarcontroller8 9 #import "RQHTabBarController.h"Ten  One @implementationRqhtabbarcontroller A @synthesizeselectedbtn;//can also be written with a bool value to take the inverse -  -- (void) Viewdidload the {    -      -CGRect rect = self.tabBar.frame;//get the size of Tabbar. -[Self.tabbar Removefromsuperview];//Remove the Tabbar of the system +      -     //Create a view to replace the Tabbar location +UIView *myview = [UIViewNew]; AMyview.frame = CGRectMake (0, rect.origin.y- -, Rect.size.width, rect.size.height+ -); at [Self.view Addsubview:myview]; -      -Uiimageview *background =[[Uiimageview alloc]initwithframe:myview.bounds]; -Background.image = [UIImage imagenamed:@"Backgroundtabbar"]; - [MyView Addsubview:background]; -      in      for(intI=0; i<3; i++) { -UIButton *btn = [UIButtonNew]; toNSString *imagename = [NSString stringWithFormat:@"tabbar%d", i +1];  +NSString *imagenamesel = [NSString stringWithFormat:@"Tabbar%dsel", i +1];  -          the [btn setimage:[uiimage imagenamed:imagename] forstate:uicontrolstatenormal];  * [btn setimage:[uiimage Imagenamed:imagenamesel] forstate:uicontrolstateselected]; $CGFloat x = i * myView.frame.size.width/5; Panax NotoginsengBtn.frame = CGRectMake (x,0, MyView.frame.size.width/5, myview.frame.size.height+Ten);  -          the [MyView addsubview:btn];  +          ABtn.tag = i;//set the tag of the button to easily index the current button and jump to the corresponding view the          +         //The listening method with parameters remember to add "colon" - [btn addtarget:self Action: @selector (CLICKBTN:) forcontrolevents:uicontroleventtouchupinside];  $          $         //The first button is selected when the setting is just entered -         if(0==i) { -btn.selected =YES;  theSELF.SELECTEDBTN = BTN;//Set this button as the selected button -         }  Wuyi      the     } -      Wu      - } About  $- (void) CLICKBTN: (UIButton *) button { -     //1. First set the previously selected button to unchecked -self.selectedBtn.selected =NO;  -     //2. Then set the current button to selected Abutton.selected =YES;  +     //3. Finally assign the current button to the previously selected button theSELF.SELECTEDBTN =button;  -      $     //4. Jump to the corresponding view controller. (using the Selectindex parameter to set the selected controller) theSelf.selectedindex =Button.tag;  the }   the  the @end

----------------------------------------

I miss the one that I can't go back to

----------------------------------------

ios-Custom Tabbar

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.