美文网首页
iOS学习之导航栏右侧放置两个按钮

iOS学习之导航栏右侧放置两个按钮

作者: 鑫飞 | 来源:发表于2019-05-06 11:50 被阅读0次
    @property(nonatomic,strong)UIBarButtonItem *mapBtn;//第一个
    
    @property(nonatomic,strong)UIBarButtonItem *messageBtn;//第二个
    
    //第一个
    -(UIBarButtonItem *)mapBtn{
    
        if (!_mapBtn) {
    
            UIButton *btn  = [UIButton buttonWithType:UIButtonTypeCustom];
            [btn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
            [btn setImage:[UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e637", 23, __kColorGray)] forState:UIControlStateNormal];
            [btn sizeToFit];
           _mapBtn =  [[UIBarButtonItem alloc] initWithCustomView:btn];
            
        }
        return _mapBtn;
    }
    
    //第二个
    -(UIBarButtonItem *)messageBtn{
    
        if (!_messageBtn) {
    
            UIButton *btn  = [UIButton buttonWithType:UIButtonTypeCustom];
            [btn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
            [btn setImage:[UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e69a", 25, __kColorGray)] forState:UIControlStateNormal];
            [btn sizeToFit];
    
             _messageBtn =  [[UIBarButtonItem alloc] initWithCustomView:btn];
            
        }
        return _messageBtn;
    }
    
    //显示
    - (void)viewDidLoad {
        
        [super viewDidLoad];
    
    //间隙
    UIBarButtonItem *fixedSpaceBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
        fixedSpaceBarButtonItem.width = 12;
        
        self.navigationItem.rightBarButtonItems = @[self.messageBtn,fixedSpaceBarButtonItem,self.mapBtn];
    
    }
    
    

    感谢:https://www.jianshu.com/p/f874326c6c44

    相关文章

      网友评论

          本文标题:iOS学习之导航栏右侧放置两个按钮

          本文链接:https://www.haomeiwen.com/subject/toricqtx.html