首页 > 代码库 > iOS toolbar

iOS toolbar

初学ios,对toolbar初步了解:

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;

 上述代码出来效果: