2012-06-03 36 views

回答

0

我發現我自己的解決方案:

float offset = 210.0f; 

UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, offset, 44.01)]; 

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools]; 

[tools release]; 
0

您需要自定義視圖添加到導航欄的-titleView

self.navigationItem.titleView = someLabel; 
+0

它將標籤添加到忽略標籤框架的相同位置。 – nik

2

將它添加到左邊的按鈕項:

UIView *mCustView = [[UIView alloc] initWithFrame:CGRectMake(0,0,200,20)]; 

mCustView.backgroundColor = [UIColor redColor]; 

UILabel *mTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0,200,20)]; 

mTextLabel.backgroundColor = [UIColor blueColor]; 

mTextLabel.font = [UIFont systemFontOfSize:20]; 

mTextLabel.textColor = [UIColor blackColor]; 

mTextLabel.text = @"Random text tested here, so sit back and enjoy"; 

[mCustView addSubview:mTextLabel]; 

[mTextLabel release]; 


UIBarButtonItem *mCustomBarItem = [[UIBarButtonItem alloc] initWithCustomView:mCustView]; 

self.navigationItem.leftBarButtonItem = mCustomBarItem; 

[mCustView release]; 
+0

非常感謝,它的工作原理,但有一個問題,舊標籤也存在,如果我刪除它,所以不會有標籤在水龍頭吧。 – nik

+0

刪除中間的標題:self.navigationItem.title = @「」;或self.navigationItem.title = nil; ? –

+0

對,我知道,但它從標籤欄的底部也刪除標籤 – nik

1

我想你可以使用UIBarButtonSystemItemFixedSpace提供增加的一種方式導航欄中的固定填充:

UIBarButtonItem *fixedSpaceItem = [[[UIBarButtonItem alloc] 
            initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace 
            target:nil 
            action:NULL] 
            autorelease]; 
fixedSpaceItem.width = 50; 
UIBarButtonItem *cancelItem = [[[UIBarButtonItem alloc] 
           initWithBarButtonSystemItem:UIBarButtonSystemItemCancel 
           target:nil 
           action:NULL] 
           autorelease]; 
// vc is some view controller 
vc.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects: 
             fixedSpaceItem, 
             cancelItem, 
             nil]; 

This will righ t縮進「取消」按鈕50分。

+0

這是如何回答我的問題??? – nik

+0

對不起,我誤解了你的問題,認爲你想改變左邊或右邊項目的縮進。 –