我有以下問題:我在包括UIImageViews的UIScrollView中生成子視圖UIView。設置UIImageView大小?
NSArray *bilder = [[NSArray alloc] initWithObjects:@"lol.jpg", @"lol2.jpg", nil];
NSArray *added = [[NSMutableArray alloc] init];
UIImageView *tmpView;
for (NSString *name in bilder) {
UIImage *image = [UIImage imageNamed:name];
tmpView = [[UIImageView alloc] initWithImage:image];
tmpView.contentMode = UIViewContentModeScaleAspectFit;
tmpView.frame = CGRectMake(0, 0, 300, 300);
[added addObject:tmpView];
[tmpView release];
}
CGSize framy = mainFrame.frame.size;
NSUInteger x = 0;
for (UIView *view in added) {
[mainFrame addSubview:view];
view.frame = CGRectMake(framy.height * x++, 0, framy.height, framy.width);
}
mainFrame.scrollEnabled = YES;
mainFrame.pagingEnabled = YES;
mainFrame.contentSize = CGSizeMake(framy.height * [added count], framy.width);
mainFrame.backgroundColor = [UIColor blackColor];
我從數組中獲取圖像文件名。現在我想調整imageview的大小,但它不起作用。有什麼建議?
感謝+視
我試過這個,圖像大小調整工作,但imagebiréw保持全屏。我怎麼能調整圖像大小調整大小的圖像? – Tronic 2010-04-23 07:44:51
在調用'[[UIImageView alloc] initWithImage:image]'之前,您是否調整了圖像大小?我閱讀'initWithImage:'的文檔的方式,應該使'UIImageView'匹配圖像大小。 – Isaac 2010-04-23 08:58:37
是的,其實我使UIImage *圖像= [UIImage imageNamed:名稱];然後UIImage * smallImage = [image scaleToSize:CGSizeMake(100,100)];然後我用tmpView = [[UIImageView alloc] initWithImage:smallImage]分配UIIMageView; 但imageview保持全屏,使用背景顏色設置! – Tronic 2010-04-23 09:12:15