UIBarButtonItem 自定义

 [self.navigationController setNavigationBarHidden:YES animated:NO];//去掉头部bar

    [self.navigationController setToolbarHidden:NO animated:NO];  //显示底部bar


 
    UIImage *title_bg = [UIImage imageNamed:@"homeToolBarBg.png"];  //获取图片
    CGSize titleSize = self.navigationController.navigationBar.bounds.size;  //获取Navigation Bar的位置和大小
    title_bg = [UtilsHelper scaleToSize:title_bg size:titleSize];//设置图片的大小与Navigation Bar相同
 
 

    mEditController = [[EditViewController alloc] init];
    
    UIButton *delBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [delBtn setFrame:CGRectMake(60, self.view.frame.size.height-16-25, 25, 25)];
    [delBtn setImage:[UIImage imageNamed:@"homeDelete.png"] forState:UIControlStateNormal];
    [delBtn addTarget:self action:@selector(delItemAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *delBarBtn = [[UIBarButtonItem alloc]initWithCustomView:delBtn];
    [delBtn setShowsTouchWhenHighlighted:YES];//设置发光
    
    UIButton *playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [playBtn setFrame:CGRectMake(60, self.view.frame.size.height-16-25, 25, 25)];
    [playBtn setImage:[UIImage imageNamed:@"homePlay.png"] forState:UIControlStateNormal];
    [playBtn addTarget:self action:@selector(playItemAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *playBarBtn = [[UIBarButtonItem alloc]initWithCustomView:playBtn];
    [playBtn setShowsTouchWhenHighlighted:YES];//设置发光
    
    UIButton *shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [shareBtn setFrame:CGRectMake(60, self.view.frame.size.height-16-25, 25, 25)];
    [shareBtn setImage:[UIImage imageNamed:@"homeShare.png"] forState:UIControlStateNormal];
    [shareBtn addTarget:self action:@selector(shareItemAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *shareBarBtn = [[UIBarButtonItem alloc]initWithCustomView:shareBtn];
    [shareBtn setShowsTouchWhenHighlighted:YES];//设置发光
     
    UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [addBtn setFrame:CGRectMake(60, self.view.frame.size.height-16-25, 25, 25)];
    [addBtn setImage:[UIImage imageNamed:@"homeAdd.png"] forState:UIControlStateNormal];
    [addBtn addTarget:self action:@selector(addItemAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *addBarBtn = [[UIBarButtonItem alloc]initWithCustomView:addBtn];
    [addBtn setShowsTouchWhenHighlighted:YES];//设置发光
    
 
    UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
 
    [self setToolbarItems:[NSArray arrayWithObjects:flexItem, delBarBtn, flexItem, playBarBtn, flexItem, shareBarBtn, flexItem, addBarBtn , flexItem, nil]];
 
    self.navigationController.toolbar.translucent=YES;
    [self.navigationController.toolbar setBackgroundImage:title_bg forToolbarPosition:0 barMetrics:0];//设置底部bar背景图片

你可能感兴趣的:(ios,uibarbuttonitem)