標籤:style blog color io os ar for sp div
ios 下自訂導覽列的BarButtonItem 會產生一些位移問題,
解決方案: 通過建立一個系統的帶固定距離的Item來調節你的Item
#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];}
IOS7 自訂UIBarButtonItem 的一些問題