我正在尝试使用此代码
向我的导航栏添加重新加载按钮- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *butt = [UIButton buttonWithType:UIButtonTypeCustom];
[butt setImage:[UIImage imageNamed:@"reload.png"] forState:UIControlStateNormal];
[butt addTarget:self action:@selector(reloadNews) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *reloadButton = [[UIBarButtonItem alloc]initWithCustomView:butt];
self.navigationItem.rightBarButtonItem = reloadButton;
[reloadButton release];
}
在iPhone 3GS设备上运行正常(使用iOS4)但在模拟器和iPhone 4设备上也没有显示png(iOS4也是如此)。 有什么想法吗?
顺便说一句:这与我拿电话的方式无关; - )
答案 0 :(得分:0)
通过设置如下框架来修复它:
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *butt = [UIButton buttonWithType:UIButtonTypeCustom];
[butt setImage:[UIImage imageNamed:@"reload2.png"] forState:UIControlStateNormal];
[butt addTarget:self action:@selector(reloadNews) forControlEvents:UIControlEventTouchUpInside];
//added the following line
butt.frame = CGRectMake(0, 0, 30, 30);
UIBarButtonItem *reloadButton = [[UIBarButtonItem alloc]initWithCustomView:butt];
self.navigationItem.rightBarButtonItem = reloadButton;
[reloadButton release];
}