Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone RightBarButtonim信息按钮,右侧无空格_Iphone_Space_Uinavigationitem_Rightbarbuttonitem - Fatal编程技术网

Iphone RightBarButtonim信息按钮,右侧无空格

Iphone RightBarButtonim信息按钮,右侧无空格,iphone,space,uinavigationitem,rightbarbuttonitem,Iphone,Space,Uinavigationitem,Rightbarbuttonitem,我设置了一个UIViewController,在其UINavigationItem右侧显示一个信息按钮,如下所示: UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; [infoButton addTarget:self action:@selector(toggleAboutView) forControlEvents:UIControlEventTouchUpInside]; self.naviga

我设置了一个
UIViewController
,在其
UINavigationItem
右侧显示一个信息按钮,如下所示:

UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[infoButton addTarget:self action:@selector(toggleAboutView) forControlEvents:UIControlEventTouchUpInside]; 
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:infoButton] autorelease];
这很好用,但唯一的问题是按钮右侧几乎没有空间,看起来很难看:

有没有办法让按钮从右边移出大约5像素


谢谢。

尝试设置infoButton.contentEdgeInsets(或imageEdgeInsets);差不多

infoButton.contentEdgeInsets = (UIEdgeInsets){.right=10};
我不确定它是否适用于“系统”按钮,但它可能会

如果这不起作用,最简单的方法可能是将其粘贴到UIView中

编辑:工具栏可能会调用
[customView sizeThatFits:blah]
以了解视图“想要的大小”。上述代码的意思应该是“添加一个10像素的右边缘插入”,这对于一个普通(自定义)按钮也会使大小增加10像素


看起来UIButton为标准信息按钮返回了一个固定的大小,忽略了任何插入。您的代码通过影响contentRectForBounds:和imageRectForContentRect:方法来“工作”,这会更改图标的绘制位置,但实际上不会更改按钮的大小。我怀疑图标在按钮外绘制,这可能意味着“可触摸”矩形是错误的(但工具栏似乎增加了普通UIBarButtonims的触摸矩形,所以可能没关系)。

我觉得它的间距合适。看看其他在导航栏右侧放置按钮的iPhone应用程序:消息、日历、联系人、地图等。它们的间距都是相同的。我的客户希望它更远一些,而信息按钮的间距看起来不太好。我在导航栏上使用相同的按钮,但在左侧而不是右侧,使用默认间距。我觉得很好。如果你的客户想让它更加突出,问问他们为什么希望他们的应用程序看起来与其他所有使用导航栏上的信息按钮的应用程序完全不同。哈,这很管用!我不知道为什么,但它奏效了。想给我解释一下吗?编辑:这段代码并没有完成所有工作,我必须添加以下内容:
infoButton.contentEdgeInsets=(UIEdgeInsets){.left=-10},否则按钮将从右侧挤压。
infoButton.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 10);