我正在尝试使用自定义图像为我的导航栏制作一个按钮。当我运行以下代码时,该按钮会正常显示,只是您可以在它后面看到另一个更宽的按钮,突出两侧。我如何摆脱其他按钮?
UIBarButtonItem *emailButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"emailBut"]
style:UIBarButtonSystemItemCompose
target:self
action:@selector(emailSheet)];
self.navigationItem.rightBarButtonItem = emailButton;
最佳答案
嗯... UIBarButtonSystemItemCompose
是一个系统图标,所以我猜你可能将你的图标覆盖在它上面。您应该为您的 style:
参数使用 UIBarButtonItemStylePlain
(或其他样式)。
编辑:
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(...)];
[button setBackgroundImage:someImage];
[button addTarget:self action:@selector(something:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
[self.navigationItem setRightBarButtonItem:barButtonItem];
关于ios - 自定义按钮 initWithImage 在自定义图像后面显示默认按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11837479/