UINavigationController详解(三)UIToolBar

来源:互联网 发布:清朝皇帝 知乎 编辑:程序博客网 时间:2024/04/29 01:12
@创建ToolBar 
    1.  方法一:自己创建
    UIToolbar *toolBar=[[UIToolbar alloc]initWithFrame:CGRectMake(0,568-49,320,49)];

    toolBar.barStyle=UIBarStyleBlack;    // 不限死,很多类型 

   [self.view addSubview:toolBar];

    2. 方法二:显示 navigationController 自带的ToolBar

    //显示工具栏(没动画效果)

    self.navigationController.toolbarHidden =NO;

    //显示工具栏(动画效果推出)

    [self.navigationController setToolbarHidden:NO animated:YES];

--------------------------------------------------------------------------------------------------------------------------------

    self.navigationController.toolbar------->toolbar是 UINavigationController 的一个属性


@给ToolBar上加内容

       UIBarButtonItem *addItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:nil];

       UIBarButtonItem *saveItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:nil];

       UIBarButtonItem *editItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:nil];

    NSArray *items=[NSArray arrayWithObjects:addItem,saveItem,editItem,nil];

    [self
setToolbarItems:items];             //向UIToolBar添加UIBarButtonItem    

    //为了使按钮与按钮之间有间距  (这2个也属于BarButtonSystemItem)

     UIBarButtonSystemItemFlexibleSpace           表示系统给一个合适的宽度
     UIBarButtonSystemItemFixedSpace                用户可以自己定义个宽度

    

     // 设置toolBar的背景图片,ios5之后的方法

     self.navigationController.toolbarsetBackgroundImage:<#(UIImage *)#> forToolbarPosition:<#                        (UIBarPosition)#> barMetrics:<#(UIBarMetrics)#>

0 0
原创粉丝点击