我的目标是在程序中通过编程方式更改作为IBOutlet使用的UIBarButton的图像。
我在stackoverflow上找到了这个解决方案change-image-of-uibutton-with-other-image,但在iOS 4.2上不起作用。
有人能帮帮我吗。 Simon
我尝试过:
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];
UIImage *image = [UIImage imageNamed:@"play.png"];
- Tommy