美文网首页
导航条左边按钮左移动

导航条左边按钮左移动

作者: sttech | 来源:发表于2017-05-11 16:05 被阅读0次

一般在开发总,使用self.navigationItem.leftBarButtonItem得到的位置不一定满足设计的需要,那么如果我们要让导航条返回按钮在向左移动5个像素如何实现呢?寻求设计帮忙是一个办法,单总不是最终的解决办法

-(UIButton *)navBarLeftBut
{
    if (!_navBarLeftBut) {
        _navBarLeftBut = [[UIButton alloc] init];
        _navBarLeftBut.titleLabel.font = TITLE_FONT(14);
        [_navBarLeftBut setTitleColor:GETCOLOR(@"007AFF") forState:UIControlStateNormal];
        // 设置为左对齐
        _navBarLeftBut.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _navBarLeftBut.frame = CGRectMake(0, 0, 40, 40);
        _navBarLeftBut.contentMode = UIViewContentModeLeft;
        [_navBarLeftBut addTarget:self action:@selector(leftButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        _navBarLeftBut.titleLabel.font = [UIFont systemFontOfSize:15];
        _navBarLeftBut.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        /*
         
         _navBarLeftBut.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
         _navBarLeftBut.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
         
         */
        // 图片左右不对称
        
//        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_navBarLeftBut];
        
        // 是的左对齐
        UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                           target:nil action:nil];

             negativeSpacer.width = -5;
 
        
        UIBarButtonItem  * right  = [[UIBarButtonItem alloc] initWithCustomView:_navBarLeftBut];
        // 通过这种设置可以实现返回按钮左移动5个像素
        self.navigationItem.leftBarButtonItems = @[negativeSpacer,right];
        
    }return _navBarLeftBut;
}

我是使用自定义的方法来实现的 可以看代码


屏幕快照 2017-05-11 16.01.34.png

相关文章

网友评论

      本文标题:导航条左边按钮左移动

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