关于自定义导航条UIBarButtonItem偏移的问题
在自定义导航条左按钮的时候发现按钮的位置向右偏移,下面给出了解决方法
主要还依赖于UIButton的属性设置
// 设置导航条的左按钮
UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
leftButton.frame = CGRectMake(0, 0, 32, 26);
leftButton.imageEdgeInsets = UIEdgeInsetsMake(0, -13, 0, 0);// 设置按钮图片的偏移位置(向左偏移)
[leftButton setImage:[UIImage imageNamed:@"shouye-cehua"] forState:UIControlStateNormal];
[leftButton addTarget:self action:@selector(handleLeftButtonAction:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];