自定义UIToolbar

UIToolbar *myToolBar = [[UIToolbar alloc] initWithFrame:
                            CGRectMake(0.0f0.0f320.0f44.0f)];
    NSMutableArray *myToolBarItems = [NSMutableArray array];
    [myToolBarItems addObject:[[UIBarButtonItem alloc]
                                initWithTitle:@"myTile"
                                style:UIBarButtonItemStylePlain
                                target:self
                                action:@selector(action)]];
    
    //在UIToolBar上面添加image
    [myToolBarItems addObject:[[UIBarButtonItem alloc]
                                initWithImage:[UIImage imageNamed:@"myImage.png"]
                                style:UIBarButtonItemStylePlain
                                target:self
                               action:@selector(action)]];
     
     //在UIToolBar上面添加SystemItem
     [myToolBarItems addObject:[[UIBarButtonItem alloc]
                                 initWithBarButtonSystemItem:UIBarButtonSystemItemPlay
                                 target:self
                                 action:@selector(action)]];
 
     //加一个进度条UIProgressView//添加自定义东西要,initWithCustomView
     UIProgressView *myProgress = [[UIProgressView alloc] initWithFrame:CGRectMake(65.0f20.0f90.0f10.0f)];  
     UIBarButtonItem *myButtonItem = [[UIBarButtonItem alloc]initWithCustomView:myProgress];  
     [myToolBarItems addObject: myButtonItem];
    
     [myToolBar setItems:myToolBarItems animated:YES];
     [self.view addSubview:myToolBar];//or set toolbar show  no hidden
posted @ 2013-11-12 15:08  0xdbe  阅读(491)  评论(0编辑  收藏  举报