是否可以在 iPhone 上的 UIToolBar 上放置一个按钮?
我想在 UIToolBar 的中心位置放置一个按钮。我必须在以下代码中进行哪些更改?
CGRect toolbarFrame = CGRectMake(0, 0, self.view.frame.size.width, 44);
UIToolbar *mytoolbar = [[UIToolbar alloc] initWithFrame:toolbarFrame];
mytoolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
mytoolbar.tintColor = [UIColor blackColor];
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:@"button 1"
style:UIBarButtonItemStylePlain target:self action:nil];
NSMutableArray *tools = [[NSMutableArray alloc] initWithObjects:button,nil];
[mytoolbar setItems:tools];
[self.view addSubview:mytoolbar];
I want to put a button on UIToolBar at the center position. What changes do I have to make in the following code?
CGRect toolbarFrame = CGRectMake(0, 0, self.view.frame.size.width, 44);
UIToolbar *mytoolbar = [[UIToolbar alloc] initWithFrame:toolbarFrame];
mytoolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
mytoolbar.tintColor = [UIColor blackColor];
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:@"button 1"
style:UIBarButtonItemStylePlain target:self action:nil];
NSMutableArray *tools = [[NSMutableArray alloc] initWithObjects:button,nil];
[mytoolbar setItems:tools];
[self.view addSubview:mytoolbar];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建一个
UIBarButtonSystemItemFlexibleSpace
类型的栏按钮。Create one bar button of
UIBarButtonSystemItemFlexibleSpace
type.我认为如果您使用 initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace 创建两个 UIBarButtonItems,并将一个放在按钮之前,另一个放在按钮之后 - 您将获得所需的居中位置...
I think if you create two UIBarButtonItems, using initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace, and put one before your button, and the other after -- you'll get the centering that you desire...