我在下面声明了一个 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/