我使用以下命令在工具栏的中心添加了一个按钮:
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:nil];
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
self.toolbarItems = @[spacer, addButton, spacer];但添加的按钮并不完全居中:

这里发生什么事情?
发布于 2012-08-11 09:08:48
不要在数组中添加两次相同的间隔符--每次的值可能不同--生成两个间隔符。
发布于 2013-10-01 03:38:14
我开始认为这是一种iOS范围的bug。或者他们在很多地方都搞错了。例如,主页上的分页点没有居中。通知中心顶部的3个按钮(今天、全部、错过)也有几个像素。更多的是这样的。因此,这可能会在下一次更新中得到纠正。
现在,我会试着强制它居中(比如,在viewWillAppear中)。下面的伪代码,没有时间测试:P:
self.toolbarItems[1].center = CGPointMake(self.bounds.size.width / 2.0f, self.bounds.size.height / 2.0f);https://stackoverflow.com/questions/11909089
复制相似问题