iOS Dev-23 toolbar toolbar and ToolbarItems: similar to Navigationbar and Navigationitem, with emphasis on how to lay out the elements of the toolbar

Source: Internet
Author: User
Tags set background

(1) Toolbar property, ToolbarItems similar to the previous Navigationbar, Navigationitem. Just ToolbarItems no navigationitem of the left and right to distinguish, it is a person in their own work, the equivalent of no subordinate.


(2) can be set a lot on the toolbar, such as background color, background image, background style, size position (but some seem to be invalid), of course, and Navigationbar, Whether it is displayed or hidden is controlled by its father, the Navigationcontroller.


(3) The main point is: we can use ToolbarItems to set the toolbar button, our General app see the following 3-4 options such as "Home", "settings" These can be loaded as Uibarbuttonitem object on this toolbar, of course, From the ToolbarItems name, it's a "s", so we have to put a separate Uibarbuttonitem object into an array and assign the array to ToolbarItems.


(4) and in this process, we recognize a very important uibarbuttonitem, it is the system comes with, before we talked about the camera, reply these systems bring their own buttons, this time said Uibarbuttonsystemitemflexiblespace , strictly speaking it is not a qualified bar button, but a free-scale area, similar to a spring, the rest of the place is full of it to shrink some, not fill it larger. It's used to lay out our uibarbuttonitem. When we have two uibarbuttonitem, we add one uibarbuttonsystemitemflexiblespace to the other, and they are centered, If there are three, guess how to do it.


We did the experiment on the root view controller of the navigation controller, so this part of the code is posted here (of course, You will create a navigation controller in APPDELEGATE.M and set the object that we instantiate below Viewcontroller as the root view controller, and turn the Self.window rootviewcontroller into this navigation controller to display normally, see the previous two sections):

#import "ViewController.h" @interface Viewcontroller () @end @implementation viewcontroller-(void) Viewdidload {//    Set Toolbarhidden hide and show, both methods can be self.navigationcontroller.toolbarhidden=no;    [Self.navigationcontroller Settoolbarhidden:no Animated:yes];    Set Toolbarhidden background color//[self.navigationcontroller.toolbar setbartintcolor:[uicolor Redcolor]];    This does not seem to work (set background)//[self.navigationcontroller.toolbar Setbackgroundcolor:[uicolor Orangecolor];    Set Toolbarhidden style, black, black transparent and so on, but it seems to be translucent effect [self.navigationController.toolbar setbarstyle:uibarstyleblack]; Set the Toolbarhidden background picture, Fortoolbarposition is where the position state is placed when it is displayed, uibarmetricsdefault whether the state setting is displayed on a vertical screen or a horizontal screen [ Self.navigationController.toolbar setbackgroundimage:[uiimage imagenamed:@ "Navigationbar.png"] fortoolbarposition    : Uibarpositionbottom Barmetrics:uibarmetricsdefault];        Can be set position, but seemingly no effect self.navigationcontroller.toolbar.frame=cgrectmake (0, 0, 375, 44); The point is to set the buttons above//and set Navigationbaritem similar//set a uibarbut firstTonitem, then make an array and assign the array to Self.toolbaritems Uibarbuttonitem *btn1=[[uibarbuttonitem Alloc]    Initwithbarbuttonsystemitem:uibarbuttonsystemitemadd target:self Action:nil]; Uibarbuttonitem *btn2=[[uibarbuttonitem alloc]initwithbarbuttonsystemitem:uibarbuttonsystemitembookmarks Target:    Self Action:nil]; Uibarbuttonitem *btn3=[[uibarbuttonitem alloc]initwithbarbuttonsystemitem:uibarbuttonsystemitemcompose Target:    Self Action:nil]; Uibarbuttonitem *btn4=[[uibarbuttonitem Alloc]initwithbarbuttonsystemitem:uibarbuttonsystemitemflexiblespace    Target:self Action:nil];    Nsarray *arr1=[[nsarray alloc]initwithobjects:btn4,btn1,btn4,btn2,btn4,btn3,btn4, nil];        SELF.TOOLBARITEMS=ARR1;    Self.view.backgroundcolor=[uicolor Purplecolor];    [Super Viewdidload]; Do any additional setup after loading the view, typically from a nib.} @end

Cut a Picture:


iOS Dev-23 toolbar toolbar and ToolbarItems: similar to Navigationbar and Navigationitem, with emphasis on how to lay out the elements of the toolbar

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.