自定义导航栏右边两个图标按钮

- (void)setNarRightView {
    UIButton *listButton = [[UIButton alloc]initWithFrame:CGRectMake(0,0,14,16)];
    [listButton setImage:IMAGENAMED(@"game_against_list") forState:UIControlStateNormal];
    [listButton addTarget:self action:@selector(listClicked:) forControlEvents:UIControlEventTouchUpInside];

    UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 17, 13)];
    UIButton *msgButton = [[UIButton alloc]initWithFrame:CGRectMake(0,0,17,13)];
    [msgButton setImage:IMAGENAMED(@"game_msg") forState:UIControlStateNormal];
    [msgButton addTarget:self action:@selector(msgClicked:) forControlEvents:UIControlEventTouchUpInside];
    [baseView addSubview:msgButton];
    _msgLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, -10, 16, 16)];
    _msgLabel.textAlignment = NSTextAlignmentCenter;
    _msgLabel.text = @"19";
    _msgLabel.font = [UIFont systemFontOfSize:10];
    _msgLabel.textColor = [UIColor whiteColor];
    _msgLabel.backgroundColor = QHRedColor;
    _msgLabel.layer.cornerRadius = 8;
    _msgLabel.layer.masksToBounds = YES;
    
    [baseView addSubview:_msgLabel];


    UIBarButtonItem *saveBitem=[[UIBarButtonItem alloc]initWithCustomView:listButton];
    UIBarButtonItem *shareBitem=[[UIBarButtonItem alloc]initWithCustomView:baseView];
    UIBarButtonItem *spaceBar = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    spaceBar.width=20;//间隔做用
    
    self.navigationItem.rightBarButtonItems=@[shareBitem,spaceBar,saveBitem];
}

效果图:ide

相关文章
相关标签/搜索