我可以使用setBackgroundVerticalPositionAdjustment更改自定義條形按鈕項的y,但是如何更改水平位置?如何更改BarButtonItem的水平位置
[viewController.navigationItem.rightBarButtonItem setBackgroundVerticalPositionAdjustment:50 forBarMetrics:UIBarMetricsDefault];
我可以使用setBackgroundVerticalPositionAdjustment更改自定義條形按鈕項的y,但是如何更改水平位置?如何更改BarButtonItem的水平位置
[viewController.navigationItem.rightBarButtonItem setBackgroundVerticalPositionAdjustment:50 forBarMetrics:UIBarMetricsDefault];
您可以使用自定義視圖創建欄按鈕,並在該視圖中創建自己的佈局。它可以只是簡單的UIButton,你可以在UIButton中設置edgeInsets。
看到Customization of UINavigationBar and the back button
F.E.
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setBackgroundImage:[UIImage imageNamed:@"chk_back.png"] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(BackBtn) forControlEvents:UIControlEventTouchUpInside];
UIView *customView = [[[UIView alloc] initWithFrame:CGRectMake(0,0, 50, 38)] autorelease];
btn.frame = CGRectMake(10, 3, 30, 32); // where you can set your insets
[customView addSubview:btn];
UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithCustomView:customView];
或者您也可以在酒吧後或befor您欄項目
UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil
action:nil];
[fixedSpace setWidth:20];
添加一些fixedSpace您可以更改rightBarButtonItem
的imageInsets
。
例如:
[viewController.navigationItem.rightBarButtonItem setImageInsets:UIEdgeInsetsMake(0, 0, 0, 50)];