在项目开发的过程中,每当苹果出新的系统版本就是我们最忙的时候,到处测试界面的问题,烦!!!
最近总是觉得自己自定义的返回按钮向右偏移20的问题,解决方法如下:
if(@available(iOS11.0, *)) {
//iOS11.0以上
UIButton*leftBtn = [[UIButtonalloc]initWithFrame:CGRectMake(0,0,20,40)];
//leftBtn.backgroundColor = [UIColor blueColor];
leftBtn.contentEdgeInsets=UIEdgeInsetsMake(0, -10,0,0);//根据自己的要求设置
leftBtn.imageEdgeInsets=UIEdgeInsetsMake(0,-8,0,0);//根据自己的要求设置
[leftBtnsetImage:[UIImageimageNamed:@"title_btn_back"]forState:UIControlStateNormal];
[leftBtnaddTarget:selfaction:@selector(backShowSchoolListVc)forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem*leftItem = [[UIBarButtonItemalloc]initWithCustomView:leftBtn];
self.navigationItem.leftBarButtonItems=@[leftItem];
}else{
//自定义左边的按钮
UIButton*leftButton = [[UIButtonalloc]init];
leftButton.frame=CGRectMake(0,0,20,20);
[leftButtonsetBackgroundImage:[UIImageimageNamed:@"title_btn_back"]forState:UIControlStateNormal];
[leftButtonaddTarget:selfaction:@selector(backShowSchoolListVc)forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem*leftBarButtonItems = [[UIBarButtonItemalloc]initWithCustomView:leftButton];
//解决按钮不靠左 靠右的问题.
UIBarButtonItem*nagetiveSpacer = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpacetarget:nilaction:nil];
nagetiveSpacer.width= -15;//这个值可以根据自己需要自己调整
self.navigationItem.leftBarButtonItems=@[nagetiveSpacer, leftBarButtonItems];
}