如何创建动态UIImageView

时间:2010-07-05 10:29:00

标签: objective-c cocoa xcode uiimageview

我想为特殊情况(if-condition)创建一个UIImageView,例如“Trend.jgp”。我尝试了各种方法与CGRectMake,但我无法动态创建这个图片到一个特殊的地方。此外,我不能像开发人员文档中描述的那样使用函数setimage。

有没有人知道如何实现我的计划?

2 个答案:

答案 0 :(得分:4)

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Trend"]];
imageView.frame = CGRectMake(....) or  imageView.center = CGPointMake(...)

将此视图添加到容器视图中,即[myView addSubview:imageView];

答案 1 :(得分:0)

UIImageView *imageView = nil;
if (specialCase) {
  imageView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @"Trend.jpg"]];
} else {
  //whatever you want to do in the other case
}