ios 下自定義導航欄的BarButtonItem 會產生一些偏移問題,ios
解決方案: 經過新建一個系統的帶固定距離的Item來調節你的Itemide
#define IOS7_NAVI_SPACE -10 } [self.navigationItem setLeftBarButtonItems:[self getBackBarButtonitem]]; } //返回按鈕 -(NSArray *)getBackBarButtonitem{ //自定義button UIButton *button=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 55, 35)]; //設置背景圖片 [button setBackgroundImage:[UIImage imageNamed:@"nav_left_btn_unselected.png"] forState:UIControlStateNormal]; //設置文字 [button setTitle:@"返回" forState:UIControlStateNormal]; button.titleLabel.font=[UIFont systemFontOfSize:13]; //設置文字顏色 [button setTintColor:[UIColor whiteColor]]; //爲TouchUpInside添加行爲 [button addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside]; //初始化一個BarbuttonItem UIBarButtonItem *Item=[[UIBarButtonItem alloc] initWithCustomView:button]; //在初始化一個系統的帶有固定距離的佔位的BarButtonItem 佔位用 UIBarButtonItem *fixedSpace=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil]; fixedSpace.width=IOS7_NAVI_SPACE;//設置寬度
// 把帶固定距離的Item放在前面,調整距離 return [[NSArray alloc] initWithObjects:fixedSpace,Item, nil]; }