iOS toolbar

时间:2014-05-13 19:51:16   收藏:0   阅读:350

初学ios,对toolbar初步了解:

bubuko.com,布布扣
self.navigationItem.title=@"显示工具栏";
    // 显示工具栏
    //self.navigationController.toolbarHidden = NO;
    [self.navigationController setToolbarHidden:NO];
    
    //设置 toolbar的背景图片, 参数:背景图,什么位置显示(),什么模式显示(横屏,竖屏)
    //[self.navigationController.toolbar setBackgroundImage:[UIImage imageNamed:@"1.jpg"] forToolbarPosition:UIToolbarPositionBottom barMetrics:UIBarMetricsDefault];
    
    self.navigationController.toolbar.frame = CGRectMake(0, 0, 320, 44);
    
    //通过toolbaritems来设置工具栏的显示项,数组中是UIBarButtonItem的实例
    UIBarButtonItem *item1 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:nil];
    UIBarButtonItem *item2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:nil];
    
    //item 的间隔,不会显示出来,会自动计算间隔
    UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    NSArray *items = [NSArray arrayWithObjects:spaceItem, item1,spaceItem,item2,spaceItem, nil];
    
    self.toolbarItems = items;
bubuko.com,布布扣

 上述代码出来效果:

bubuko.com,布布扣

 

iOS toolbar,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!