iOS Basics (12) Use of--uinavgationcontroller (iii) ToolBar

Source: Internet
Author: User

The Uitoolbar exists in the Uinavigationcontroller navigation bar controller and is hidden by default, and the Toolbarhidden property of the Uinavigationcontroller is set to display Uitoolbar.

first, the setting of Uitoolbar1, in the ROOTVIEWCONTROLLER.MViewdidload methodAdd code to the

[Self.navigationcontroller Settoolbarhidden:no Animated:yes];

Show Bottom Toolbar

2. Set Uitoolbar property: (used after iOS7)

    // set the trace color    [Self.navigationController.toolbar Setbartintcolor:[uicolor Greencolor];

// set a background picture    [Self.navigationController.toolbar setbackgroundimage:[uiimage imagenamed:@ "40-15092z94009  "] fortoolbarposition:uibarpositionbottom Barmetrics:uibarmetricsdefault];    

3. Create Uibarbuttonitem
Uibarbuttonitem *left = [[Uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemreply target: Nil Action:nil];         *center = [[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemcompose target:nil action: Nil];         *right = [[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemdone target:nil Action:nil];         // blank    uibarbuttonitem *blank = [[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem: Uibarbuttonsystemitemflexiblespace Target:nil Action:nil];
4. add Uibarbuttonitem for Uitoolbar

1) Create an array itemsarray;

2) Add Uibarbuttonitem on the array;

3) pass Itemsarray to Uitoolbar;

    Nsarray *itemsarray = @[left, blank, center, blank, right];    [Self settoolbaritems:itemsarray];

Second, custom Uitoolbar

1. Hidden System toolbar: added in Rootviewcontroller.m viewdidload method

    [Self.navigationcontroller Settoolbarhidden:yes Animated:yes];

Add the new toolbar to the view, and set an item for Toobar,

Uibarbuttonitem*one = [[Uibarbuttonitem alloc] initwithimage:[uiimage imagenamed:@""] Style:uibarbuttonitemstyleplain Target:nil Action:nil]; Uibarbuttonitem*two = [[Uibarbuttonitem alloc] initwithimage:[uiimage imagenamed:@""] Style:uibarbuttonitemstyleplain Target:nil Action:nil]; Nsarray*buttons =@[one,two]; ToolBar= [[Uitoolbar alloc] initWithFrame: (cgrect) {0.0, Self.view.frame.size.height-toolbar.frame.size.height-44.0, Self.view.frame.size.width,44.0}]; Toolbar.autoresizingmask=Uiviewautoresizingflexibletopmargin;    [ToolBar Setbarstyle:uibarstyledefault];    [ToolBar setitems:buttons];    [Self.view Addsubview:toolbar]; 

Uinavigationcontroller's introduction to this place is over.

iOS Basics (12) Use of--uinavgationcontroller (iii) 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.