关闭

IOS之【UIToolbar】

标签: ios开发objective-cuiview
866人阅读 评论(0) 收藏 举报
分类:

#import "OneViewController.h"


@interface OneViewController ()


@end


@implementation OneViewController


- (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;

    toolBar.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;

    [itemsaddObject:addItem];

    

    

    // 弹簧  UIBarButtonSystemItemFlexibleSpace

    UIBarButtonItem *spaceItem = [[[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpacetarget:nilaction:nil]autorelease];

    [itemsaddObject:spaceItem];

    

    // 联系人

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

    contactItem.enabled =NO;

    [itemsaddObject:contactItem];

    

    // 弹簧

    UIBarButtonItem *spaceItem2 = [[[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpacetarget:nilaction:nil]autorelease];

    [itemsaddObject:spaceItem2];

    

    // 删除

    UIBarButtonItem *deleteItem = [[[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrashtarget:selfaction:@selector(delete)]autorelease];

    deleteItem.style =UIBarButtonItemStyleBordered;

    [itemsaddObject:deleteItem];

    

    toolBar.items = items;

    

    [self.viewaddSubview:toolBar];

    [toolBarrelease];

}


- (void)didReceiveMemoryWarning

{

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:615505次
    • 积分:9225
    • 等级:
    • 排名:第1983名
    • 原创:272篇
    • 转载:235篇
    • 译文:14篇
    • 评论:31条
    博客专栏
    最新评论