setImage:forState: 在 iOS 3.2 中不起作用
预期的行为是在单击播放操作时更改图像(从播放到暂停以及从暂停到播放)。这在 4.x 版本中按预期工作。在版本 3.2 中,setImage 不起作用,这意味着 setImage 不设置图像。在 3.2 版本中,调用 imageForState:UIControlStateNormal 返回 null。有什么想法吗?
@interface TestViewController : UIViewController {
IBOutlet UIButton *playButton;
BOOL play;
}
- (IBAction) play:(id)sender;
@end
@implementation TestViewController
- (IBAction) play:(id)sender {
if (play == YES) {
[playButton setImage:[UIImage imageNamed:@"pause"] forState:UIControlStateNormal];
play = NO;
} else {
[playButton setImage:[UIImage imageNamed:@"play"] forState:UIControlStateNormal];
play = YES;
}
//[playButton imageForState:UIControlStateNormal]
}
@end
The expected behavior is to change the image (from play to pause and from pause to play) when the play action is clicked. This works as expected in version 4.x. In version 3.2 the setImage does not work meaning the setImage does not set the image. Call to imageForState:UIControlStateNormal returns null in 3.2 version. Any ideas?
@interface TestViewController : UIViewController {
IBOutlet UIButton *playButton;
BOOL play;
}
- (IBAction) play:(id)sender;
@end
@implementation TestViewController
- (IBAction) play:(id)sender {
if (play == YES) {
[playButton setImage:[UIImage imageNamed:@"pause"] forState:UIControlStateNormal];
play = NO;
} else {
[playButton setImage:[UIImage imageNamed:@"play"] forState:UIControlStateNormal];
play = YES;
}
//[playButton imageForState:UIControlStateNormal]
}
@end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的代码看起来正确,您是否检查过是否在 XIB 文件中为按钮连接了 IBOutlet?
Your code looks correct, have you checked that you connected up the IBOutlet in your XIB file for your button?
UIImage
的imageNamed
接受带有扩展名的图像名称,即如果您将代码更改为
您的代码将按照您的期望工作。
UIImage
'simageNamed
takes in a image name with extension i.e if you change your codeto
your code will work as per your expectations.