ios - 在 IOS 7 中为 UIToolBar 设置标题

标签 ios ios7 uibarbuttonitem uitoolbar

我在下面声明了一个 UIToolBar 按钮:

UIToolbar *toolbar = [[UIToolbar alloc] init];
toolbar.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, 64.0);

我还有一个 UIBarButtonItem,它被添加到左侧作为后退按钮。但是,我该如何向 UIToolbar 添加一个居中的标签标题呢?

最佳答案

UILabel *lblTitle = [[UILabel alloc] initWithFrame:CGRectMake(50, 50, 150, 20)];
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.textColor = [UIColor blackColor];
lblTitle.textAlignment = NSTextAlignmentLeft;
[self.view addSubview:lblTitle];
UIBarButtonItem *typeField = [[UIBarButtonItem alloc] initWithCustomView:lblTitle];   
toolBar.items = [NSArray arrayWithArray:[NSArray arrayWithObjects:backButton,spaceBar,lblTitle, nil]];

我认为这将解决您的问题。

关于ios - 在 IOS 7 中为 UIToolBar 设置标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19489293/

相关文章:

iphone - 如何使用 block 一步一步完成方法?

ios - application:didFinishLaunchingWithOptions没有被调用

ios7 - Windows 身份验证和 iOS7

iOS 7 UITabBar 角标(Badge)位置

ios - 切换到 Swift 4 后 BarButtonItem 格式错误

ios - 使用 Swift 在 UIWebView 中旋转 PDF

ios - 关闭 SKScene 后,内存仍然很高

ios - 我怎样才能保护自己免受这次崩溃 *** -[__NSArrayM objectAtIndex :]: index 1 beyond bounds [0 . 。 0]?

ios - 调整 UIBarButtonItem 的 Imageview 的大小,以便按比例缩小图像 (iOS)

ios - 具有减少的 alpha 的 UIToolBar,希望 UIBarButtonItem 具有 alpha 1