如何从类中显示UIImageView

时间:2011-11-01 21:01:24

标签: iphone ios cocoa-touch

我有一个名为myClass的班级,其中包含UIImageView imgView和其他版本。如何在界面构建器中显示该视图?

很抱歉,如果问题不是很确切,我是iOS开发的新手。问我任何问题。

2 个答案:

答案 0 :(得分:2)

您需要在myClass.h中将其声明为IBOutlet:

@property (retain, nonatomic) IBOutlet UIImageView *imgView;

然后,您可以将插座连接到界面构建器中的属性。请参见下面的示例:

enter image description here

答案 1 :(得分:2)

首先,您可以将UIImageView拖入xib文件,而不是与IBOutlet UIImageView成员类挂钩。 在编写代码后,改变图像视图变量。 您要显示的图像必须位于资源或支持文件中。

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSString *filePath = [[NSBundle mainBundle] pathForResource:imageName ofType:@"jpg"];
    UIImage *image = [UIImage imageWithContentsOfFile:filePath];
    imageView.image = image;

}