標籤:
//在-(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;
}
iOS_自訂返回按鈕