IOS 11th Lesson Tab Bar to achieve the same effect as QQ bottom

Source: Internet
Author: User
Tags reserved uikit




0: First, or through the pure code to achieve

0: Delete 3 files Viewcontroller.h,viewcontroller.m,main.storyboard

1: Modify click on the blue button on the left, then select general-"Developer info-" main interface, will this main interface clear sky
1: Then generate four view controllers first Second third fourth, and a category

Firstviewcontroller:

FIRSTVIEWCONTROLLER.M//Ellevenbiaoqianlan/////Created by thousand Ya Dad on 16/10/27. COPYRIGHT©2016 year Kodulf.
All rights reserved. #import "FirstViewController.h" #import "FourthViewController.h" @interface Firstviewcontroller () @end @implementa
    tion Firstviewcontroller-(void) viewdidload {[Super viewdidload];
    Do no additional setup after loading the view.
    [Self settitle:@ "a"];
    [Self.view Setbackgroundcolor:[uicolor Yellowcolor]]; NSLog (@ "First:%s", __func__)//Print method name//Add a push button, and then click the Navigation bar after the point does not show Self.navigationItem.rightBarButtonItem =[[ui Barbuttonitem alloc] initwithtitle:@ "PUSH" Style:uibarbuttonitemstyleplain target:self action: @selector (

Pushcontroller)];
    }-(void) pushcontroller{fourthviewcontroller *FOURTHVC = [[Fourthviewcontroller alloc]init];
    
    Hide the following tab bar [FOURTHVC Sethidesbottombarwhenpushed:yes];
[Self.navigationcontroller PUSHVIEWCONTROLLER:FOURTHVC Animated:yes]; }-(void) Didreceivememorywarning {[Super didreceivememorywarning];
Dispose of any of the can is recreated. }/* #pragma mark-navigation//In a storyboard-based application, you'll often want to do a little preparation Re Navigation-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {//Get the new view controller US
    ing [Segue Destinationviewcontroller].
Pass the selected object to the new view controller.
 } * * @end

Secondviewcontroller

////SECONDVIEWCONTROLLER.M//Ellevenbiaoqianlan///Created by thousand Ya Dad on 16/10/27.//Copyright© 2016 Kodulf.
All rights reserved. #import "SecondViewController.h" @interface Secondviewcontroller () @end @implementation Secondviewcontroller-(v
    OID) viewdidload {[Super viewdidload];
    Do no additional setup after loading the view.
    [Self settitle:@ "Second"];
    [Self.view Setbackgroundcolor:[uicolor Redcolor]];
    NSLog (@ "Second:%s", __func__);//Print Method name}-(void) didreceivememorywarning {[Super didreceivememorywarning];
Dispose of any of the can is recreated. }/* #pragma mark-navigation//In a storyboard-based application, you'll often want to do a little preparation Re Navigation-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {//Get the new view controller US
    ing [Segue Destinationviewcontroller].
Pass the selected object to the new view controller. } */@end 


Thirdviewcontroller

////THIRDVIEWCONTROLLER.M//Ellevenbiaoqianlan///Created by thousand Ya Dad on 16/10/27.//Copyright© 2016 Kodulf.
All rights reserved. #import "ThirdViewController.h" @interface Thirdviewcontroller () @end @implementation Thirdviewcontroller-(void
    ) Viewdidload {[Super viewdidload];
    Do no additional setup after loading the view.
    [Self settitle:@ "third"];
    [Self.view Setbackgroundcolor:[uicolor Bluecolor]];
    NSLog (@ "Third:%s", __func__);//Print Method name}-(void) didreceivememorywarning {[Super didreceivememorywarning];
Dispose of any of the can is recreated. }/* #pragma mark-navigation//In a storyboard-based application, you'll often want to do a little preparation Re Navigation-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {//Get the new view controller US
    ing [Segue Destinationviewcontroller].
Pass the selected object to the new view controller. } */@end 


Fourthviewcontroller

//  fourthviewcontroller.m
//  Ellevenbiaoqianlan////
Created by  thousand ya dad on 16/10/27.  copyright©2016 year Kodulf. All rights reserved.

#import "FourthViewController.h"

@interface fourthviewcontroller ()

@end

@implementation Fourthviewcontroller

-(void) viewdidload {
    [super viewdidload];
    Do no additional setup after loading the view.
    [Self settitle:@ "fourth"];
    [Self.view Setbackgroundcolor:[uicolor Browncolor]];
}

-(void) didreceivememorywarning {
    [super didreceivememorywarning];
    Dispose of any of the can is recreated.
}
/* #pragma mark-navigation

//In a storyboard-based application, your'll often want to do a little preparatio N Before navigation
-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {
    //get the new view Controller using [Segue Destinationviewcontroller].
    Pass the selected object to the new view controller.
}
* *

@end


Uiimage+originalimage

//  uiimage+originalimage.h
//  Ellevenbiaoqianlan////
Created by  thousand ya dad on 16/10/27.  copyright©2016 year Kodulf. All rights reserved.

#import <UIKit/UIKit.h>
//The default image above is done with the effect of hair glass, if you do not want the effect of hair glass, so long direct

@interface UIImage ( Originalimage)
+ (UIImage *) Originalimagename: (NSString *) name;
@end

//  UIIMAGE+ORIGINALIMAGE.M
//  Ellevenbiaoqianlan////
Created by  thousand ya dad on 16 /10/27.  copyright©2016 year Kodulf. All rights reserved.

#import "uiimage+originalimage.h"

@implementation uiimage (originalimage)
//default image above is done with the effect of the hair glass , if you do not want the effect of the hair glass, so long direct

+ (UIImage *) Originalimagename: (NSString *) name{return
    [[UIImage Imagenamed:name] Imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];
}

@end


2: Then modify the app delegate.m file

APPDELEGATE.M//Ellevenbiaoqianlan/////Created by thousand Ya Dad on 16/10/27. COPYRIGHT©2016 year Kodulf.
All rights reserved. #import "AppDelegate.h" #import "FirstViewController.h" #import "SecondViewController.h" #import " ThirdViewController.h "//default above pictures are done with the effect of hair glass, if you do not want the effect of hair glass, so long direct///import the classification we created #import" Uiimage+originalimage.h "@ Interface Appdelegate () @end @implementation appdelegate-(BOOL) Application: (UIApplication *) Application Didfinishla Unchingwithoptions: (nsdictionary *) launchoptions {//navigation bar Controller is a form of stack,//tag bar controller, it's kind of like the Viewpager and Radiogroup knot in Android Combined form, but it's different, the tab bar controller inside the component, for example, there is a navigation bar controller, there are other, will show only some in front, some in the back, equivalent to the display of side by side, please check the description of the figure//Our one board is to set the navigation bar controller to the label Bar Controller's Child controller/ First, create a class of four controllers, then a uiimage+originalimage category [self Setwindow:[[uiwindow alloc]initwithframe:[uiscreen Mainscree
    N].bounds]];
    [Self.window makekeyandvisible];
    Uitabbarcontroller *tabbarcontroller = [[Uitabbarcontroller alloc] init]; [Tabbarcontroller.view SetBackgroundColor: [Uicolor Whitecolor]];
    
    [Self.window Setrootviewcontroller:tabbarcontroller];
    Firstviewcontroller *firstvc=[[firstviewcontroller Alloc]init]; Place first on top of the Navigationcontroler, then add navigationcontroller to FirstVC.tabBarItem.title = @ "I"//Underground description of the text Firstv C.tabbaritem.image = [UIImage imagenamed:@ "64"];//default picture//firstvc.tabbaritem.selectedimage =[UIImage " Cat "];//after the selected effect//default image above is done by the effect of the hair glass, if you do not want the effect of hair glass, so long direct//here and the selection and by-election in the display of the selector is very similar to the Android Firstvc.tabbaritem . SelectedImage =[uiimage originalimagename:@ "Cat"];//selected effect Uinavigationcontroller = [
    
    Uinavigationcontroller ALLOC]INITWITHROOTVIEWCONTROLLER:FIRSTVC];
    Direct copy and paste above the top-generated second third secondviewcontroller *SECONDVC = [[Secondviewcontroller alloc]init];
    SecondVC.tabBarItem.title =@ "Second";
    SecondVC.tabBarItem.image = [UIImage imagenamed:@ "64"];
    Secondvc.tabbaritem.selectedimage=[uiimage originalimagename:@ "Cat"];Uinavigationcontroller *secondnavigationcontroller = [[Uinavigationcontroller alloc]initwithrootviewcontroller:
    
    SECONDVC];
    Thirdviewcontroller *THIRDVC = [[Thirdviewcontroller alloc]init];
    ThirdVC.tabBarItem.title = @ "Third";
    ThirdVC.tabBarItem.image =[uiimage imagenamed:@ "64"];
    ThirdVC.tabBarItem.selectedImage = [UIImage originalimagename:@ "Cat"]; Uinavigationcontroller *thirdnavigationcontroller = [[Uinavigationcontroller alloc]initwithrootviewcontroller:
    
    THIRDVC];
    You can also set the background picture and color to Tabbar [Tabbarcontroller.tabbar setbackgroundimage:[uiimage imagenamed:@ "Green2"]];
    
    [Tabbarcontroller.tabbar Setbackgroundcolor:[uicolor Greencolor]]; Unify the font size [[Uitabbaritem appearance] Settitletextattributes:@{nsfontattributename:[uifont Systemfontofsize:13]}
    Forstate:uicontrolstatenormal]; [Tabbarcontroller Setviewcontrollers:@[navigationcontroller,secondnavigationcontroller,
    Thirdnavigationcontroller]]; The default Tabbar selection is the first//lazy load to be added to the arrayThe way that you use to add to which, and once loaded will not easily be recycled//But if the memory warning occurs, then the system will prioritize those currently unavailable interface//Override point for customization after a
    Pplication launch.
return YES; }-(void) Applicationwillresignactive: (uiapplication *) application {//Sent when the application was about to move FR Om Active to inactive state. This can occur for certain types of temporary interruptions (such as a incoming phone call or SMS message) or the US
    Er quits the application and it begins the transition to the background state. Use the To pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates.
Games should to pause the game. }-(void) Applicationdidenterbackground: (uiapplication *) Application { , save user data, invalidate timers, and store enough application state information to restore your application to its cur
    Rent state in case it is terminated later. If your application supports background EXECUtion, this is called instead of Applicationwillterminate:when the user quits. }-(void) Applicationwillenterforeground: (uiapplication *) application {//called as part of the transition from the Background to the inactive state;
Here you can undo many of the changes made on entering the background.  }-(void) Applicationdidbecomeactive: (uiapplication *) application {//Restart any tasks this were paused (or not yet started) while the application is inactive.
If the application is previously in the background, optionally refresh the user interface. }-(void) Applicationwillterminate: (uiapplication *) application {//called when the application was about to Terminat E. Save data if appropriate.
Also applicationdidenterbackground:.
 } @end







Related Article

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.