【发布时间】:2017-12-07 08:08:34
【问题描述】:
我的目标是以编程方式更改 UIBarButton(我用作 IBOutlet)的图像。
我在 stackoverflow change-image-of-uibutton-with-other-image 上找到了这个解决方案。但这不适用于 iOS 4.2。
谁能帮帮我。 西蒙
我试过了:
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];
【问题讨论】:
标签: iphone image ios4 uibarbuttonitem