Two ways to "ios dev-31" uitabbar background, icon color, selected background settings, and hidden Uitabbar
Source: Internet
Author: User
<span id="Label3"></p><p><p><strong>I. Some settings for the Uitabbar background and icon icons</strong></p></p><p><p><br></p></p><p><p>(1) because the background color set directly to the Uitabbar is not pure. Translucent feel, So sometimes we can directly use the solid color picture as the background to achieve the desired effect.</p></p><p><p><br></p></p><p><p>(2) It is also important to change the color of the icon image to one of the useful methods, the default is Blue.</p></p><p><p><br></p></p><p><p>In the APPDELEGATE.M file: (one navigation Controller and 5 view Controllers)</p></p><p><p></p></p><pre code_snippet_id="480223" snippet_file_name="blog_20141007_1_4155056" name="code" class="objc">-(BOOL) application: (uiapplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions {// Create 5 view controllers and one navigation controller ViewController1 *vc1=[[viewcontroller1 alloc]init]; Uinavigationcontroller *nav1=[[uinavigationcontroller alloc]initwithrootviewcontroller:vc1]; ViewController2 *vc2=[[viewcontroller2 alloc]init]; ViewController3 *vc3=[[viewcontroller3 alloc]init]; ViewController4 *vc4=[[viewcontroller4 alloc]init]; ViewController5 *vc5=[[viewcontroller5 alloc]init]; Viewcontroller *vc6=[[viewcontroller alloc]init]; 6 titles [email protected] "interface 1"; [email protected] "interface 2"; [email protected] "interface 3"; [email protected] "interface 4"; [email protected] "interface 5"; [email protected] "interface 6"; 6 System icon Icons [nav1.tabbaritem initwithtabbarsystemitem:uitabbarsystemitemtoprated tag:1]; [vc2.tabbaritem Initwithtabbarsystemitem:uitabbarsystemitemsearch tag:2]; [vc3.tabbaritem Initwithtabbarsystemitem:uitabbarsystemitemcontaCTS tag:3]; [vc4.tabbaritem initwithtabbarsystemitem:uitabbarsystemitemmostviewed tag:4]; [vc5.tabbaritem initwithtabbarsystemitem:uitabbarsystemitemmostrecent tag:5]; [vc6.tabbaritem initwithtabbarsystemitem:uitabbarsystemitemdownloads tag:6]; Create a view controller array and assign it to the Viewcontrollers value of the tab bar controller Nsarray *arr1=[[nsarray alloc]initwithobjects:nav1,vc2,vc3,vc4,vc5, vc6, nil]; Uitabbarcontroller *tbcon1=[[uitabbarcontroller alloc]init]; tbcon1.viewcontrollers=arr1; The tab bar Controller has a tabbar property, which has two items and SelectedItem properties that are not available. Since these two properties are managed directly by the tag bar controller, Others cannot assign values to them//execute the following two lines of code, the program Crashes//tbcon1.tabbar.items=[[nsarray alloc]initwithobjects: vc1.tabbaritem, nil]; tbcon1.tabbar.selecteditem=vc1.tabbaritem; Through BackgroundColor can set the label bar color, but is a layer of faint red tbcon1.tabbar.backgroundcolor=[uicolor redcolor]; You can set the background color for the tab bar by setting the background image. For example, a red background image. Require the image size to be right//in the following way to obtain the width of the tab bar, create a background picture, and then introduced in NSLog (@ "%i,%i", (int) tbCon1.tabBar.frame.size.height, (int) tbCon1.tabBar.frame.size.width); TbcOn1.tabbar.backgroundimage=[uiimage imagenamed:@ "tabbarbg.png"]; The icon can be set by Tintcolor color Tbcon1.tabbar.tintcolor=[uicolor redcolor]; Set the background picture of the selected label, the width is 375/5=77 tbcon1.tabbar.selectionindicatorimage=[uiimage imagenamed:@ "selectiondic.png"]; This tab bar controller as the Window's root view controller to display self.window.rootviewcontroller=tbcon1; Override point for customization after application Launch. Return YES;}</pre><br><strong><strong>second, The first way to hide Uitabbar</strong></strong><p><p></p></p><p><p><br></p></p><p><p>This method requires a navigation controller view to do the experiment, because we need to use the hidesbottombarwhenpushed property, which means that when this view is pressed into the stack (the stack of the navigation controller). Hide the bar at the Bottom. Contains uitabbar.</p></p><p><p><br></p></p><p><p>So we experimented with the above nav1, and NAV1 's root view controller was vc1. We add a button to the vc1. One click into the VIEWCONTROLLER7.M (instance is vc7), and hides the uitabbar.</p></p><p><p>In the Vc1:</p></p><p><p></p></p><pre code_snippet_id="480223" snippet_file_name="blog_20141007_2_9248795" name="code" class="objc"><pre code_snippet_id="480223" snippet_file_name="blog_20141007_2_9248795" name="code" class="objc">#import "ViewController1.h" #import "ViewController7.h" @interface ViewController1 () @end @implementation Viewcontroller1-(void) viewdidload { // UIButton *btn1=[uibutton buttonwithtype:uibuttontyperoundedrect]; Btn1.frame=cgrectmake (max., +); Btn1.backgroundcolor=[uicolor whitecolor]; [BTN1 settitle:@ "PUSH" forstate:uicontrolstatenormal]; [BTN1 addtarget:self action: @selector (jumpto) forcontrolevents:uicontroleventtouchupinside]; [self.view addsubview:btn1]; [super viewdidload]; Do any additional setup after loading the view.} -(void) jumpto{ ViewController7 *vc7=[[viewcontroller7 alloc]init]; [self.navigationcontroller PUSHVIEWCONTROLLER:VC7 animated:no];} @end</pre></pre><br>In the Viewcontroller7.m:<p><p></p></p><p><p></p></p><pre code_snippet_id="480223" snippet_file_name="blog_20141007_3_1451814" name="code" class="objc"><pre code_snippet_id="480223" snippet_file_name="blog_20141007_3_1451814" name="code" class="objc">#import "ViewController7.h" @interface ViewController7 () @end @implementation viewcontroller7//add a Initwithnibname method , the standard is return SELF. In addition, it is necessary to set its Hidesbottombarwhenpushed property at initialization to be valid for yes//. This property needs to be set before the instance of the view controller is loaded into the stack, otherwise invalid-(id) initwithnibname: (nsstring *) nibnameornil bundle: (nsbundle *) nibbundleornil{ self.hidesbottombarwhenpushed=yes; Return self;} @end</pre></pre><br><strong><strong>third, Another way to hide Uitabbar</strong></strong><p><p></p></p><p><p><br></p></p><p><p>is to move the Uitabbar Position. That is, adjust the value of the FRAME.ORIGIN.Y. Disappear is to move it out of the screen, appear is to put it back in Place.</p></p><p><p>(however, the restoration of the phenomenon, the experience is very poor, not recommended)</p></p><p><p>so, in the Viewcontroller7.m:</p></p><p><p></p></p><pre code_snippet_id="480223" snippet_file_name="blog_20141007_4_8987769" name="code" class="objc"><pre code_snippet_id="480223" snippet_file_name="blog_20141007_4_8987769" name="code" class="objc">Add a method that will attempt to appear. And in this setting move the Tabbar down. Removing the entire screen, equivalent to Disappearing-(void) viewdidappear: (BOOL) animated{ nsarray *arr1=self.tabbarcontroller.view.subviews; UIView *view1=[arr1 objectatindex:0]; Uitabbar *tabbarview1=[arr1 objectatindex:1]; The first view is a full Screen. Do not need to be full of height, so can not do whatever settings //view1.frame=cgrectmake (0, 0, 375, 667); Tabbarview1.frame=cgrectmake (0, 667, 375, 49);}</pre></pre><br>In the Viewcontroller1.m:<p><p></p></p><p><p></p></p><pre code_snippet_id="480223" snippet_file_name="blog_20141007_5_5367482" name="code" class="objc"><pre code_snippet_id="480223" snippet_file_name="blog_20141007_5_5367482" name="code" class="objc">Add a viewdidappear, move the lower tabbar up again, equivalent to restore to Place-(void) viewdidappear: (BOOL) animated{ nsarray *arr2= self.tabBarController.view.subviews; Uitabbar *TABBARVIEW2=[ARR2 objectatindex:1]; Tabbarview2.frame=cgrectmake (0, 618, 375, 49);}</pre></pre><p><p><br></p></p><p><p>Actually another way of hiding. But it's very damaging. It's all hidden from the Root. this tag controller does not display uitabbar.</p></p><p><p>Is the following second line of Code:</p></p><p><p></p></p><pre code_snippet_id="480223" snippet_file_name="blog_20141007_6_4778838" name="code" class="objc"><pre code_snippet_id="480223" snippet_file_name="blog_20141007_6_4778838" name="code" class="objc"> Uitabbarcontroller *tbcon1=[[uitabbarcontroller alloc]init]; tbcon1.tabbar.hidden=yes;</pre></pre><br><p><p></p></p>Cut a picture:<p><p></p></p><p><p><br></p></p> <p><p>Two ways to "ios dev-31" uitabbar background, icon color, selected background settings, and hidden Uitabbar</p></p></span>
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