0

アプリケーションに UIImageview があり、実際に画像を表示して、いつでも変更できるか疑問に思っていました! 私の主な問題は、まさにどこに置くかだと思います! どのコードとどこでそれが非常に役立つかを教えていただければ! ありがとう!

編集:また、背景を画像や色に実用的に変更できる場合も! ありがとう!または動作します!

EDIT2:これが私のコードです。常にエラーが発生するため、どこに配置すればよいかわかりません。

MainView.h

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@interface MainView : UIView {
    //static int r;
    int r;
    IBOutlet UIButton *myButton;
    IBOutlet UILabel *myTextLabel;
    IBOutlet UILabel *myTextLabel2;
    IBOutlet UIImageView *myImage;

}

@property (nonatomic, retain) UIButton *myButton;
@property (nonatomic, retain) UILabel *myTextLabel;
@property (nonatomic, retain) UILabel *myTextLabel2;
@property (nonatomic, retain) UIImageView *myImage;



- (IBAction)buttonclick;

//+(void) initialize;

@end

そしてその

MainView.m

#import "MainView.h"
#include <stdlib.h>
#include <libc.h>


@implementation MainView

@synthesize myButton, myTextLabel, myTextLabel2, myImage;   


- (IBAction)buttonclick {

    r++;

    if(r == 1) {

        self.myTextLabel.text = @"word";
        self.myTextLabel2.text = @"def.";

    }else if(r == 2) {

        self.myTextLabel.text = @"word2";
        self.myTextLabel2.text = @"def2 ";  
    }

}

@end
4

2 に答える 2

1

画像自体を変更するには、次のように記述できます。

UIImage* myNewImage = ...;
myImageView.image = myNewImage;

UIImageView の背景を変更するには、次のように記述できます。

myImageView.backgroundColor = [UIColor redColor];

... またはUIColor、パターンとして使用される別の画像を含め、その他の必要なもの。

于 2009-11-06T00:50:24.810 に答える
0

ビュー コントローラ クラスに viewDidLoad() メソッドを実装すると、そこでビューに画像を設定できます。このメソッドが自動的に呼び出されると、すべての IBOutlets が初期化され、myImageView.image を設定できるようになります。

viewDidLoadを参照

于 2009-11-06T05:06:33.363 に答える