一般在开发总,使用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;
}
我是使用自定义的方法来实现的 可以看代码

网友评论