[英]Set UIImageView Size?
i have following problem: i generate subviews UIView in an UIScrollView including UIImageViews. 我有以下问题:我在包含UIImageViews的UIScrollView中生成子视图UIView。
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];
i get image file names out of an array. 我从一个数组中获取图像文件名。 now i want to resize the imageview to a specific size, but it won't work. 现在我想将imageview调整为特定大小,但它不起作用。 any advice? 任何建议?
thanks + regards 谢谢+问候
Change tmpView.frame to use a new CGRect: 更改tmpView.frame以使用新的CGRect:
tmpView.frame = CGRectMake(tmpView.frame.origin.x,
tmpView.frame.origin.y,
newWidth,
newHeight);
UIImage
缺少NSImage
的setSize:
方法,但这篇文章似乎在UIImage
上添加了一个使用类别的scaleToSize:
方法。
What I see is: 我看到的是:
view.frame = CGRectMake(framy.height * x++, 0, framy.height, framy.width);
But if you look at CGRectMake... 但是如果你看看CGRectMake ......
Declaration: CGRect CGRectMake (
CGFloat x,
CGFloat y,
CGFloat width,
CGFloat height
);
You are setting the X value, not the Y value. 您正在设置X值,而不是Y值。 I expect, based on your later call to: 我希望,根据你以后的电话:
mainFrame.contentSize = CGSizeMake(framy.height * [added count], framy.width);
that you intend to make the these images appear on top of each other, not side by side. 您打算使这些图像显示在彼此之上,而不是并排显示。
Suggest: 建议:
view.frame = CGRectMake(framy.height * x++, 0, framy.height, framy.width);
to 至
view.frame = CGRectMake(0,framy.height * x++, framy.height, framy.width);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.