对齐 UIToolBar 项目
我创建了三个 UIBarButtonItem
,如下所示。 它们向左对齐,我想居中对齐,这样右侧就没有间隙。 我在 UIToolBar
上没有看到对齐属性。 还有其他方法可以实现此目的吗?
//create some buttons
UIBarButtonItem *aboutButton = [[UIBarButtonItem alloc] initWithTitle:@"About" style:UIBarButtonItemStyleBordered target:self action:@selector(showAbout:)];
[toolbar setItems:[NSArray arrayWithObjects:settingsButton,deleteButton,aboutButton,nil]];
//Add the toolbar as a subview to the navigation controller.
[self.navigationController.view addSubview:toolbar];
I have three UIBarButtonItem
created as below. They align left and I'd like to align center so there isn't a gap on the right side. I don't see an align property on UIToolBar
. Is there another way to accomplish this?
//create some buttons
UIBarButtonItem *aboutButton = [[UIBarButtonItem alloc] initWithTitle:@"About" style:UIBarButtonItemStyleBordered target:self action:@selector(showAbout:)];
[toolbar setItems:[NSArray arrayWithObjects:settingsButton,deleteButton,aboutButton,nil]];
//Add the toolbar as a subview to the navigation controller.
[self.navigationController.view addSubview:toolbar];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将两个 UIBarButtonSystemItemFlexibleSpace 项目添加到工具栏,分别位于项目的左侧和右侧
添加这些项目就像添加任何其他工具栏项目一样,将在这两个项目之间均匀分配空间。
Add two UIBarButtonSystemItemFlexibleSpace items to your toolbar, to the left and right of your items
Adding these as you would any other toolbar items will distribute space evenly between the two of them.
这也可以直接从故事板完成。
只需拖放工具栏中的项目,并将其中一些项目变成灵活或固定空间即可获得所需的效果。 请参阅下面的两个示例。
This can also be done right from a storyboard.
Just drag and drop items in the toolbar, and turn some of them into flexible or fixed space to get the desired effect. See the two examples below.
在 Xamarin iOS 中
右对齐:
居中对齐:
In Xamarin iOS
Right aligned:
Center Aligned:
Swift 版本:
Swift version: