美文网首页
IOS 导航栏右侧放置两个按钮

IOS 导航栏右侧放置两个按钮

作者: 秀_ba75 | 来源:发表于2017-09-15 16:52 被阅读687次
    @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];
    
    }
    

    相关文章

      网友评论

          本文标题:IOS 导航栏右侧放置两个按钮

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