iOS development Project-26 modifying system settings for Uitabbar

Source: Internet
Author: User
Tags uicontrol

iOS development Project-26 modifying system settings for Uitabbar

A simple explanation

1. Realistic effects in two systems of IOS6 and iOS7

2. Results required (basically consistent in IOS6 and iOS7)

Ii. setting and structure of Uitabbar

1. Try adjusting the Uitabbar

View the child controls inside the Uitabbar in the following way

View child controls inherited from:

Description: Uitabbarbutton: Inherit from Uicontrol

UIButton: Inherit from Uicontrol

Print view the internal structure of each child control

2. Modifying System Properties

Note: Under the IOS6 system

 

1 //2 //YYTABBARVIEWCONTROLLER.M3 //4 5 #import "YYTabBarViewController.h"6 #import "YYHomeTableViewController.h"7 #import "YYDiscoverViewController.h"8 #import "YYMessageViewController.h"9 #import "YYProfileViewController.h"Ten #import "Uiimage+extension.h" One #import "YYNavigationViewController.h" A  - @interfaceYytabbarviewcontroller () <UITabBarControllerDelegate> -  the @end -  - @implementationYytabbarviewcontroller -  +  -- (void) Viewdidload + { A [Super Viewdidload]; at     //Add four sub-controllers -Yyhometableviewcontroller *home=[[Yyhometableviewcontroller alloc]init]; -[Self addonechildvc:home title:@"Home Page"ImageName:@"Tabbar_home"Selectedimagename:@"tabbar_home_selected"]; -      -      -Yymessageviewcontroller *message=[[Yymessageviewcontroller alloc]init]; in[Self addonechildvc:message title:@"message"ImageName:@"Tabbar_message_center"Selectedimagename:@"tabbar_message_center_selected"]; -      toYydiscoverviewcontroller *discover=[[Yydiscoverviewcontroller alloc]init]; +[Self addonechildvc:discover title:@"found"ImageName:@"Tabbar_discover"Selectedimagename:@"tabbar_discover_selected"]; -      theYyprofileviewcontroller *profile=[[Yyprofileviewcontroller alloc]init]; *[Self addonechildvc:profile title:@"I'm"ImageName:@"Tabbar_profile"Selectedimagename:@"tabbar_profile_selected"]; $     Panax Notoginseng //self.tabbar.backgroundimage=[uiimage imagewithname:@ "Tabbar_background"]; -Self.Delegate=Self ; the   + } A  the-(void) Viewdidappear: (BOOL) Animated + { - [Super viewdidappear:animated]; $      $ [self Removebackgroundintabbarbutton]; - } -  the-(void) Removebackgroundintabbarbutton - {Wuyi      for(UIView *childinchself.tabBar.subviews) { the         //if it's not Uitabbarbutton, just get out. -         if(! [Child iskindofclass:nsclassfromstring (@"Uitabbarbutton")])Continue; Wu          -BOOL selected=NO; About  $          for(UIView *childchildinchchild.subviews) { -             if([Childchild iskindofclass:nsclassfromstring (@"Uitabbarselectionindicatorview")]) {//The description is a selected background - [Childchild Removefromsuperview]; -Selected =YES; A             } +         the             if([Childchild Iskindofclass:[uilabelclass]]) {//description is a uilable . -UILabel *label = (UILabel *) Childchild; $ //Label.font=[uifont systemfontofsize:15]; the                 if(selected) {//indicates that the button is selected and the text color is orange theLabel.textcolor=[Uicolor Orangecolor]; the}Else           //Note that this button is not selected, set the label color to black the                 { -Label.textcolor=[Uicolor Blackcolor]; in                 } the             } the         } About     } the } the  the  +-(void) TabBar: (Uitabbar *) TabBar Didselectitem: (Uitabbaritem *) Item - { the [self Removebackgroundintabbarbutton];Bayi } the      the /** - * Add a sub-controller -  * the * @param childvc Control Object the * @param title the * @param imageName icon the * @param selectedimagename the icon when selected -  */ the-(void) ADDONECHILDVC: (Uiviewcontroller *) CHILDVC title: (NSString *) title ImageName: (NSString *) ImageName Selectedimagename :(NSString *) Selectedimagename the { the     //randomly set the background color of the sub-controller94 //Childvc.view.backgroundcolor=yyrandomcolor; the      the     //Set Title theChildvc.title=title;//equivalent to setting the title of the latter two98 //Childvc.navigationitem.title=title;//set the title of the navigation bar About //Childvc.tabbaritem.title=title;//Set the caption above Tabbar -     101     //Set icon102Childvc.tabbaritem.image=[UIImage imagewithname:imagename];103     //set the icon when selected104UIImage *selectedimage=[UIImage imagewithname:selectedimagename]; the     106     107     if(iOS7) {108         //declare this picture with the original (do not render)109SelectedImage =[SelectedImage imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; the     }111ChildVc.tabBarItem.selectedImage =SelectedImage; the     113      //to add a sub-controller as a Tabbar controller theYynavigationviewcontroller *nav=[[Yynavigationviewcontroller ALLOC]INITWITHROOTVIEWCONTROLLER:CHILDVC]; the      the [self addchildviewcontroller:nav];117 118 }119  - 121 //in IOS7, the pictures of SelectedImage are rendered again in blue122 //To display the original, you have to tell it: do not render123 124 //Xcode plug-in Installation path:/users/user name/Library/Application support/developer/shared/xcode/plug-ins the @end

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.