3
Mon objectif est de changer l'image d'un UIBarButton (que j'utilise comme IBOutlet) par programmation. J'ai trouvé cette solution sur stackoverflow change-image-of-uibutton-with-other-image. mais cela ne fonctionne pas sur iOS 4.2.Changer l'image de UIBarButton
Quelqu'un peut-il m'aider avec cela. Simon
j'ai essayé:
UIImage *image = [UIImage imageWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"play" ofType:@"png"]];
playButton.image = image;
UIImage *image = [UIImage imageWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"play" ofType:@"png"]];UIImage *image = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"play" ofType:@"png"]];
CGRect frame = CGRectMake(0, 0, image.size.width, image.size.height);
UIButton* someButton = [[UIButton alloc] initWithFrame:frame];
[someButton setBackgroundImage:image forState:UIControlStateNormal];
[someButton setShowsTouchWhenHighlighted:YES];
playButton = [[UIBarButtonItem alloc]initWithCustomView:someButton];
[someButton release];
une méthode plus courte pour charger UIImage 'UIImage * image = [UIImage imageNamed: @" play.png "];' – Tommy