标签:
//在-(void)viewWillAppear:(BOOL)animated方法中添加返回按钮
//返回按钮
UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
leftButton.frame=CGRectMake(0, 0, 60, 25);
[leftButton setImage:[UIImage imageNamed:@"back_img"] forState:UIControlStateNormal];
//设置返回按钮的图片,跟系统自带的“<”符合保持一致
[leftButton addTarget:self action:@selector(back_click:) forControlEvents:UIControlEventTouchUpInside];
//图片 居左,
[leftButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
//ios7.0系统中,自定义的返回按钮 有点 偏右,需要调整位置
if(([[[UIDevice currentDevice] systemVersion] floatValue]>=7.0?20:0))
{
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil action:nil];
negativeSpacer.width = -8;//这个数值可以根据情况自由变化
self.navigationItem.leftBarButtonItems = @[negativeSpacer, leftItem];
}else
{
self.navigationItem.leftBarButtonItem = leftItem;
}
标签:
原文地址:http://www.cnblogs.com/sugeladi/p/5159690.html