views:

27

answers:

1

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.rightBarButtonItem = 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 ;-)

A: 

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

}
Kai