平时经常会遇到无论如何设置item的frame都不不能靠左或者靠右边。b不能满足PM的需求。
其实有个非常简单的办法。话不多说直接上代码。
UIImage *image = [UIImage imageNamed:@"back1"];
UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 0, 40, 30)];
backBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
[backBtn setImage:image forState:UIControlStateNormal];
[backBtn addTarget:self action:@selector(backBarButtonItemClick:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backBarItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
UIBarButtonItem * spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
spaceItem.width = -10;
self.navigationItem.leftBarButtonItems = @[spaceItem,backBarItem];