iOS build toolbar Uitoolbar

Source: Internet
Author: User

Use macros to define text entries, image entries, system entries, and custom view entries, which provide an automatic release uibarbuttonitem that can be placed into the uitoolbar.

#define Cookbook_purple_color [Uicolor colorwithred:0.20392f green:0.19607f blue:0.61176f alpha:1.0f]
#define Barbutton (TITLE, SELECTOR) [[[Uibarbuttonitem alloc] Initwithtitle:title style:uibarbuttonitemstyleplain Targ Et:self Action:selector] autorelease]
#define Imgbarbutton (IMAGE, SELECTOR) [[[Uibarbuttonitem alloc] Initwithimage:image style:uibarbuttonitemstyleplain Target:self Action:selector] autorelease]
#define Sysbarbutton (ITEM, SELECTOR) [[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:item target:self action: SELECTOR] Autorelease]
#define Custombarbutton (VIEW) [[Uibarbuttonitem alloc] Initwithcustomview:view] autorelease]


Create a toolbar

Uitoolbar *TB = [[Uitoolbar alloc] Initwithframe:cgrectmake (0.0f, 0.0f, 320.0f, 44.0f)];
Tb.center = Cgpointmake (160.0f, 200.0f);
Nsmutablearray *tbitems = [Nsmutablearray array];

[Tbitems Addobject:barbutton (@ "Title", @selector (Action))];
[Tbitems Addobject:sysbarbutton (Uibarbuttonsystemitemadd, @selector (action))];
[Tbitems Addobject:imgbarbutton ([uiimage imagenamed:@ "Tbumbrella.png"], @selector (action))];
[Tbitems Addobject:custombarbutton ([[[[[Uiswitch alloc] init] autorelease])];
[Tbitems Addobject:sysbarbutton (Uibarbuttonsystemitemflexiblespace, nil)];
[Tbitems Addobject:imgbarbutton ([uiimage imagenamed:@ "Tbpuzzle.png"], @selector (action))];

ADD Fixed pixel width
Uibarbuttonitem *bbi = [[[Uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemfixedspace target: Nil Action:nil] autorelease];
Bbi.width = 20.0f;
[Tbitems Addobject:bbi];

Tb.items = Tbitems;
[Self.view ADDSUBVIEW:TB];
[TB release];


Toolbar tip:

Working with toolbars is a useful way to use some tips.

1, fixed space can have width ----in all Uibarbuttonitem, only uibarbuutonsystemitemfixedspace entries can be assigned a width, so create a space entry, set its width, It is then added to the entry column.

2. use a flexible space for left or right alignment---starting with a uibarbuttonsystemitemflexiblespace in the entry list causes all remaining entries to align to the right. Add one at the end, then align left. With two uibarbuttonsystemitemflexiblespace, one added at the beginning and one at the end, the remaining entries are centered.

3, consider missing items-------------Hide Bar button entries according to the context, do not use only flexible space allocation to remove entries. Instead, replace the entry with a fixed-width space that matches the original size of the entry. Doing so saves the layout before and after the entry disappears and keeps all other icons in place.

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.