1

簡単に言うと、UIViewにInterfaceBuilderを使用して画像を配置しました。次に、その画像に触れているとき、たとえば別の画像をロードする必要があるときに、メソッド/関数を実行したいと思います。

私のコード:

- (void)touchesended:(NSSet*) touches withEvent:(UIEvent *)event 
{
    // UITouch *touch = [touch anyObject];
    bild_1_1.image = [UIImage imageNamed:@"t_1_4.jpg"];
}
4

4 に答える 4

2

UIImage の代わりに UIButton を配置し、TouchUpInside イベント ハンドラでメソッド setBackgroundImage:forState: を使用して背景画像を変更することで、必要なことを簡単に実行できます。

于 2010-03-12T11:09:22.887 に答える
1

別の解決策:

.h ファイル内

IBOutlet UIImagView *imageButton を配置します。

-(IBAction)doSomething:(id)sender;

.m ファイルで

-(IBAction)dosomething:(id)sender {

    // your code

   [imageButton setImage:[UIImage imageNamed:@""t_1_4.jpg"} forState:UIControlStateNormal];
}

私のコードで非常にうまく動作します

于 2012-11-14T16:21:04.420 に答える
0

it works with me without creating subclass, in .h file you add UIImageView

#import <UIKit/UIKit.h>
@interface YourClassName : UIViewController{
    IBOutlet UIImageView *wallpaper;
}
@property (nonatomic, retain) IBOutlet UIImageView *wallpaper;
@end

then in .m you can use your method

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [wallpaper setImage:[UIImage imageNamed: @"image.png"]];
}
于 2015-06-22T09:49:45.600 に答える