自定义rightBarButtonItems

-(void)addRightNavBarWithImage
{
    UIImage *image = [UIImage imageNamed:@"chatWhiteAddUsers"];
    UIImage *imageSecond = [UIImage imageNamed:@"saomiao2"];
    
    
    if (self.navigationItem.rightBarButtonItem)
    {
        self.navigationItem.rightBarButtonItem= nil;
    }
    
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, image.size.width+5, image.size.height)];
    [button setImage:image forState:UIControlStateNormal];
    [button addTarget:self action:@selector(navRightAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    UIButton * buttonSecond = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, imageSecond.size.width+5, imageSecond.size.height)];
    [buttonSecond setImage:imageSecond forState:UIControlStateNormal];
    [buttonSecond addTarget:self action:@selector(saomiao) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *rightBtnSecond = [[UIBarButtonItem alloc]initWithCustomView:buttonSecond];
    
    
    self.navigationItem.rightBarButtonItems = @[rightBtn,rightBtnSecond];
}

你可能感兴趣的:(自定义rightBarButtonItems)