因为ios7以后leftBarButtonItem往右移了大概10px,现在要使得leftBarItem和ios7之前那样显示,处理如下:
if (isBeforeIOS7) { UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = CGRectMake(15,5,22,22); [btn setBackgroundImage:[UIImage imageNamed:@"icon_back_left"] forState:UIControlStateNormal]; [btn addTarget:self action:@selector(goBackAction) forControlEvents: UIControlEventTouchUpInside]; UIBarButtonItem*backBarBtn=[[UIBarButtonItem alloc]initWithCustomView:btn]; self.navigationItem.leftBarButtonItem=backBarBtn; } else { UIBarButtonItem *backBarBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_back_left"] style:UIBarButtonItemStyleDone target:self action:@selector(goBackAction)]; UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; negativeSpacer.width = -10; self.navigationItem.leftBarButtonItems = @[negativeSpacer,backBarBtn]; }
时间: 2024-10-08 22:17:56