【发布时间】:2013-04-08 23:26:45
【问题描述】:
我在 -viewDidLoad 中有以下代码::
self.navigationController.toolbarHidden = NO;
UIBarButtonItem *shareButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(sendEmail:)];
UIBarButtonItem *spacer1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0.0 , 25, self.view.frame.size.width, 21.0f)];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor];
label.text = @"text-here";
label.userInteractionEnabled = NO;
label.font = [UIFont systemFontOfSize:18.0];
label.textAlignment = NSTextAlignmentCenter;
UIBarButtonItem *labelItem = [[UIBarButtonItem alloc] initWithCustomView:label];
self.navigationController.toolbarItems = [NSArray arrayWithObjects:shareButton, spacer1, labelItem, nil];
但是,当我加载应用程序时,工具栏仅显示共享按钮,该按钮与通过电子邮件共享应用程序的内容相关联。标签没有出现(我希望它出现)。我基本上从 stackoverflow 上提出的其他问题中复制了这个确切的代码,而且我所看到的每个地方都是相同的答案......这有什么不同吗?
我假设由于共享按钮可以正常工作,因此工具栏也可以正常工作。像我这样的问题的其他答案产生了 [self.navigationController.view addSubview:toolbarObj];,但我只是使用了与导航控制器集成的工具栏。
垫片...嗯,我现在还不知道垫片对我有多大作用。现在,如果我理解正确,垫片会将我的标签项目推到最右边,对吗?它不会均匀地隔开物体吗?我希望将标签放在工具栏的中心。
非常感谢您的帮助和解释。
【问题讨论】:
标签: objective-c text uinavigationcontroller uilabel uitoolbar