我正在使用UINavigationBar的rightBarButtonItems
屬性在我的導航欄的右側部分添加兩個按鈕。是否有可能使這兩個按鈕之間的間距更寬?在UINavigationBar中間隔rightBarButtonItems
感謝
我正在使用UINavigationBar的rightBarButtonItems
屬性在我的導航欄的右側部分添加兩個按鈕。是否有可能使這兩個按鈕之間的間距更寬?在UINavigationBar中間隔rightBarButtonItems
感謝
您可以將兩個按鈕之間添加一個UIBarButtonSystemItemFlexibleSpace
項目。
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
我是不是能夠得到靈活的空間,在我的處境工作,但這裏是我以前能夠定位rightBarButtonItem代碼:注意,我把周圍的邊框UIView的,所以你可以看到什麼它看起來像在那裏有圖像。
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(89,40,100,30)];
containerView.layer.borderColor = [[UIColor redColor] CGColor];
containerView.layer.borderWidth = 1.0;
UIImage *image = [UIImage imageNamed:@"nav-icon.png"];
UIButton *navigationButton = [UIButton buttonWithType:UIButtonTypeCustom];
[navigationButton setFrame:CGRectMake(67,0,25,25)];
[navigationButton setImage:image forState:UIControlStateNormal];
[containerView addSubview:navigationButton];
UIBarButtonItem *navigationBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:containerView];
self.navigationItem.rightBarButtonItem = navigationBarButtonItem;
謝謝,它的工作原理。但我如何指定寬度? – atnatn 2012-02-09 03:42:34
我假設我應該使用'UIBarButtonSystemItemFixedSpace':D – atnatn 2012-02-09 03:43:49
@atnatn也許'item.width'工作,我還沒有測試。 – fannheyward 2012-02-09 03:45:14