我需要在工具栏的中心添加一个按钮。我已经成功地将按钮添加到工具栏上了。我的问题如下:
1.) 我需要将这个按钮居中。它应该在工具栏的中心。
2.) 在刷新按钮图像显示后,我需要有一段文本。
toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0 , 320 , 60)];
NSMutableArray* button = [[NSMutableArray alloc] initWithCapacity:1];
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshButtonAction:)];
[button addObject:barButton];
[toolBar setItems:button animated:NO];
[self.view addSubview:toolBar];
UILabel
是UIView
的子类,所以如果符合您的需求,请创建一个并使用它。如果需要更复杂的内容,请构建自己的自定义UIView
。您也可以在 IB 中完成这个操作 ;) - Ryder MackayUIBarButtonSystemItemRefresh
后面跟着一段文本。那么你的方法能行吗?因为我将使用initWithBarButtonSystemItem
来添加“刷新”图标,然后我无法使用initWithCustomView
来添加包含标签的UIView
。 - sharon