首页 > 其他分享 >IOS之【UIToolbar】

IOS之【UIToolbar】

时间:2022-12-09 15:00:52浏览次数:34  
标签:addObject UIToolbar IOS autorelease UIBarButtonItem initWithBarButtonSystemItem 

#import "OneViewController.h"

@interface OneViewController ()

@end

@implementation

- (void)add {
NSLog(@"添加");
}

- (void)delete {
NSLog(@"删除");
}

- (void)viewDidLoad
{
[superviewDidLoad];

// self.view.backgroundColor = [UIColor blueColor];

UIToolbar *toolBar = [[UIToolbaralloc] init];
// 设置toolbar的样式
toolBar.barStyle =UIBarStyleBlackTranslucent;
CGFloat toolBarWidth =self.view.bounds.size.width;
frame =CGRectMake(0,0, toolBarWidth, 44);

// 设置toolbar的所有item
NSMutableArray *items = [NSMutableArray array];

// 添加
UIBarButtonItem *addItem = [[[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAddtarget:selfaction:@selector(add)]autorelease];
// 设置item的背景样式
addItem.style =UIBarButtonItemStyleBordered;
addObject:addItem];


// 弹簧
UIBarButtonItem *spaceItem = [[[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpacetarget:nilaction:nil]autorelease];
addObject:spaceItem];

// 联系人
UIBarButtonItem *contactItem = [[[UIBarButtonItemalloc] initWithTitle:@"联系人" style:UIBarButtonItemStylePlain target:nilaction:nil]autorelease];
enabled =NO;
addObject:contactItem];

// 弹簧
UIBarButtonItem *spaceItem2 = [[[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpacetarget:nilaction:nil]autorelease];
addObject:spaceItem2];

// 删除
UIBarButtonItem *deleteItem = [[[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrashtarget:selfaction:@selector(delete)]autorelease];
deleteItem.style =UIBarButtonItemStyleBordered;
addObject:deleteItem];

items

self.viewaddSubview:toolBar];
release];
}

- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

标签:addObject,UIToolbar,IOS,autorelease,UIBarButtonItem,initWithBarButtonSystemItem,
From: https://blog.51cto.com/u_15907570/5925325

相关文章