:
[btnthumbnail2 setImage:[UIImage imageNamed:@"leaderboard_ov.png"] forState:UIControlStateNormal];
[self showMyOtherView];
はこれを試してみてください。この特定のケースでは、私はtableViewCellの内部からやっています。これはあなたが求めているよりも多くのコードですが、私が使用したプロセス全体を示しています。ご覧のとおり、ボタンを押している間は、特別な画像が表示されないようにしました。
// Button set up, inside cellForRowAtIndexPath:
// imageFrame is just the rect that you want the button to occupy
[self setFavorite:[[UIButton alloc] initWithFrame:imageFrame]];
[[self favorite] addTarget:self action:@selector(toggleFavorite:)
forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:[self favorite]];
[self draw];
// definition of the callback specified above
- (void) toggleFavorite:(id) sender {
if (favoriteState == 0){
favoriteState = 1;
} else {
favoriteState = 0;
}
[self draw];
}
// the draw method, to set the images
// favOn and favOff are statically defined at the top of the class
- (void) draw {
if (favoriteState != 0) {
[[self favorite] setBackgroundImage:favOn forState:UIControlStateNormal];
[[self favorite] setBackgroundImage:favOn forState:UIControlStateHighlighted];
} else {
[[self favorite] setBackgroundImage:favOff forState:UIControlStateNormal];
[[self favorite] setBackgroundImage:favOff forState:UIControlStateHighlighted];
}
}
出典
2009-07-02 15:20:41
mmc
あなたはそれを押した後で、状態を変えたいと思いますか?ボタンを押し続けている間は? – John
はい、それを押した後、画像を変更する必要があります。 –