2012-06-03 40 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

对不起,我误解了你的问题,认为你想改变左边或右边项目的缩进。 –