rightBarButtonItem info button, no space to the right

旧城冷巷雨未停 提交于 2019-12-02 22:39:28
testing
infoButton.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 10);

Try setting infoButton.contentEdgeInsets (or imageEdgeInsets); something like

infoButton.contentEdgeInsets = (UIEdgeInsets){.right=10};

I'm not sure if it works for "system" buttons, but it might.

If that doesn't work, the easiest way is probably to stick it inside a UIView.

EDIT: Presumably the toolbar calls [customView sizeThatFits:blah] to find out how big the view "wants to be". The above code is supposed to mean "add a 10-pixel right edge inset", which for a normal (custom) button also makes the size bigger by 10 pixels.

It seems like UIButton returns a fixed size for the standard info button, ignoring any insets. Your code "works" by affecting the contentRectForBounds: and imageRectForContentRect: methods, which changes where the icon is drawn, but does not actually change the size of the button. I suspect that the icon is drawing outside the button, which may mean that the "touchable" rect is wrong (but toolbars seem to increase the touch rects for normal UIBarButtonItems, so maybe it doesn't matter).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!