我有一个名为myClass
的班级,其中包含UIImageView
imgView
和其他版本。如何在界面构建器中显示该视图?
很抱歉,如果问题不是很确切,我是iOS开发的新手。问我任何问题。
答案 0 :(得分:2)
您需要在myClass.h中将其声明为IBOutlet:
@property (retain, nonatomic) IBOutlet UIImageView *imgView;
然后,您可以将插座连接到界面构建器中的属性。请参见下面的示例:
答案 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;
}