ios 代码建立UIToolBar

分为4步骤flex


一、建立一个UIToolbarcode

二、建立一个NSMutableArray *buttons 用来存放UIBarButtonItem  ci

三、buttons addObject 添加  按钮get

四、[self.toolBar setItems:button];it

五、self.view 添加toolbario

代码以下table

                      action:NULL];
    //不限制大小 自适应
    self.toolBar=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 20, width, 0)];
    
    //左侧取消按钮
    UIBarButtonItem * leftBtn=[[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(back:)];
    //右侧发布按钮
    UIBarButtonItem * rightBtn=[[UIBarButtonItem alloc]initWithTitle:@"发布" style:UIBarButtonItemStylePlain target:self action:@selector(fabu:)];
    NSMutableArray * buttons=[[NSMutableArray alloc]initWithCapacity:4];
    [buttons addObject:leftBtn];
    [buttons addObject:flexibleSpaceItem1];
    [buttons addObject:rightBtn];
    [self.toolBar setItems:buttons];
    [self.toolBar sizeToFit];
    
    
        self.toolBar.backgroundColor=color;
        self.toolBar.tintColor=[UIColor whiteColor];
        [self.toolBar setBackgroundImage:[UIImage new]forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
        [self.toolBar setShadowImage:[UIImage new]
                 forToolbarPosition:UIToolbarPositionAny];
    [self.view addSubview:self.toolBar];
相关文章
相关标签/搜索