Implementation of IOS Custom Tabbar

Source: Internet
Author: User

The implementation of the effect is probably like this, the picture is not good-looking, live to see

Just stick to the code.

    1. First create a Singleview program

    2. Change Viewcontroller base class to Uitabbarcontroller

    3. Then write the. m file as follows [PS I'm open arc]

-  (void) viewdidload {    [super viewdidload];    //  Do any additional setup after loading the view, typically  from a nib.        [self initowncontrollers];     [self initowntabview];    [self.tabbar sethidden:yes];} /* * set multiple tabs, in order to toggle  **/-  (void) Initowncontrollers{    nsarray *array  = @[@ "Home", @ "more", @ "file", @ "info", @ "discover"];  //  each tab title          NSMutableArray *conArray = [[NSMutableArray alloc] init];         for  (Nsstring *object in array)  {  //   Traverse         uiviewcontroller *con = [[ uiviewcontroller alloc] init];        con.title = object;         //  set the navigation bar to show the title, which makes it easy to tell which page to switch to         uinavigationcontroller  *controll = [[UINavigationController alloc] initWithRootViewController:con];         [conArray addObject:controll];    }         self.viewcontrollers = conarray;} /* *  defines its own tabbar **/-  (void) initowntabview{    uiview *view  = [[uiview alloc] initwithframe:cgrectmake (5, 519, 310, 44)]; //  Use the latest xcode, coordinate a bit of a problem, adjust it yourself     view.backgroundColor = [UIColor whiteColor];     view.layer.cornerRadius = 9; //  set rounded corners, nice points          //  load each button's picture     nsarray *imagearray = @[@ "Home.png", @ "Much.png", @ "file.png", @ "Message.png", @ " Discover.png "];    for  (int index = 0; index < [ imagearray count]; index++)  {        uibutton * button = [uibutton buttonwithtype:uibuttontypesystem];         [button setimage:[uiimage imagenamed:imagearray[index]] forstate: Uicontrolstatenormal];        [button addtarget:self action: @selector (pagechanged:)  forControlEvents:UIControlEventTouchDown];         button.frame = cgrectmake (21+index*62, 7, 30, 30);  //  This coordinate should be set correctly                  button.tag = index;   //  set Tag  to conveniently set switch pages         [view addSubview:button];     }        [self.view addsubview:view];} -  (void) pagechanged: (uibutton *) button{    self.selectedindex =  button.tag;   //  the event handling of its own button}



Implementation of 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.