Emi*_*mil 9 iphone space rightbarbuttonitem uinavigationitem
我有一个UIViewController
设置在右边显示一个信息按钮,UINavigationItem
如下所示:
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[infoButton addTarget:self action:@selector(toggleAboutView) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:infoButton] autorelease];
Run Code Online (Sandbox Code Playgroud)
这是完美的,但唯一的问题是我在按钮右侧留下很少甚至没有空间,这看起来很难看:
按钮是否有任何方法可以从右侧移动约5像素?
谢谢.
tes*_*ing 17
infoButton.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 10);
Run Code Online (Sandbox Code Playgroud)
tc.*_*tc. 14
尝试设置infoButton.contentEdgeInsets(或imageEdgeInsets); 就像是
infoButton.contentEdgeInsets = (UIEdgeInsets){.right=10};
Run Code Online (Sandbox Code Playgroud)
我不确定它是否适用于"系统"按钮,但它可能.
如果这不起作用,最简单的方法可能是将它放在UIView中.
编辑:大概是工具栏调用[customView sizeThatFits:blah]
以找出视图"想成为"的大小.上面的代码应该表示"添加一个10像素的右边缘插入",这对于普通(自定义)按钮也会使尺寸大10像素.
似乎UIButton为标准信息按钮返回固定大小,忽略任何插入.您的代码通过影响contentRectForBounds:和imageRectForContentRect:方法来"工作",这些方法会更改绘制图标的位置,但实际上不会更改按钮的大小.我怀疑图标是在按钮外面绘制的,这可能意味着"可触摸"的矩形是错误的(但是工具栏似乎增加了普通UIBarButtonItems的触摸范围,所以可能没关系).
归档时间: |
|
查看次数: |
5980 次 |
最近记录: |