开发者

Why does UIBarButtonItem not show the Image on Iphone 4

I'm trying to add a reload button to my navigation bar using this code

- (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.rightBarButtonIte开发者_开发百科m = reloadButton;
   [reloadButton release]; 

}

which work fine on iPhone 3GS device (with iOS4) but doesn't show the png on simulator and iPhone 4 device (iOS4 as well). Any ideas?

BTW: It's independent of how I hold the Phone ;-)


Fixed it by setting the frame like this:

- (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];  

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜