【发布时间】:2013-12-02 08:54:35
【问题描述】:
更新 - 一种可能的解决方案
根据 Alexander Merchi 在这篇文章 (UIBarButtonItem Custom view in UINavigationBar) 中给出的答案,找到了解决方案。但是还是不知道如何正确改变图片的位置。
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(0, 0, 28.0f, 28.0f)]; // 28 points is the width or height of the button image
[btn setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(onClickMenuButton) forControlEvents:UIControlEventTouchUpInside];
btnMenu = [[UIBarButtonItem alloc] initWithCustomView:btn];
原帖
在 iOS 6 中,目标是这样的:
虽然目前的结果是这样的:
我的代码是
btnMenu = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"button.png"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(onClickMenuButton)];
button.png 这个是白色的圆圈,里面有三个白色的条,背景是透明的。
【问题讨论】:
-
在我的回答中更改 leftButton.bounds。它应该可以改变位置。
标签: ios uinavigationbar customization