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 回答