2010-07-05 77 views
1

我想創建一個UIImageView,例如對於特殊情況(if-condition)的「Trend.jgp」。我嘗試過使用CGRectMake的各種方法,但是我無法動態地將此圖片創建到特定位置。此外,我不能像開發人員文檔中描述的那樣使用setimage函數。如何創建一個動態UIImageView

有沒有人知道如何實現我的計劃?

回答

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

這種觀點添加到您的容器視圖,即[myView addSubview:imageView];

+0

非常感謝你!我的計劃現在可行! – Jonathan 2010-07-05 11:07:24

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