首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIBarButtonItem未居中

UIBarButtonItem未居中
EN

Stack Overflow用户
提问于 2012-08-11 04:53:14
回答 2查看 1.1K关注 0票数 2

我使用以下命令在工具栏的中心添加了一个按钮:

代码语言:javascript
复制
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];

但添加的按钮并不完全居中:

这里发生什么事情?

EN

回答 2

Stack Overflow用户

发布于 2012-08-11 09:08:48

不要在数组中添加两次相同的间隔符--每次的值可能不同--生成两个间隔符。

票数 0
EN

Stack Overflow用户

发布于 2013-10-01 03:38:14

我开始认为这是一种iOS范围的bug。或者他们在很多地方都搞错了。例如,主页上的分页点没有居中。通知中心顶部的3个按钮(今天、全部、错过)也有几个像素。更多的是这样的。因此,这可能会在下一次更新中得到纠正。

现在,我会试着强制它居中(比如,在viewWillAppear中)。下面的伪代码,没有时间测试:P:

代码语言:javascript
复制
self.toolbarItems[1].center = CGPointMake(self.bounds.size.width / 2.0f, self.bounds.size.height / 2.0f);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11909089

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档