IOS UIToolbar 工具条实例

作者:朱克锋

邮箱:[email protected]

转载请注明出处:http://blog.csdn.net/linux_zkf


//按钮初始化类型

1initWithTitle

2initWithImage

3initWithBarButtonSystemItem

4initWithCustomView


#define BARBUTTON(TITLE, SELECTOR) [[[UIBarButtonItem alloc] initWithTitle:TITLE style:UIBarButtonItemStylePlain target: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]

- (void) action

{

}

{

//初始化

UIToolbar *tb = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];

tb.center = CGPointMake(160.0f, 200.0f);

//初始化items

NSMutableArray *tbitems = [NSMutableArray array];

//添加items

[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))];

// 添加fix

UIBarButtonItem *bbi = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil] autorelease];

bbi.width = 20.0f;

[tbitems addObject:bbi];

//items赋给toolbar

tb.items = tbitems;

//

[self.view addSubview:tb];

[tb release];

}

你可能感兴趣的:(ios,image,action,工具)