0

I am trying to center a UIImageView in a scroll view. Here is the code I tried with no results.

UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:kReceiptDetailScrollViewBackgroundCornered]];
[iv setContentMode:UIViewContentModeCenter];
[[self scrollView] insertSubview:iv atIndex:0];

Anybody know what's wrong with this?

4

1 回答 1

1

您将图像视图的内容模式设置为居中,这意味着图像不会缩放,并且可以大于显示它的图像视图。

UIImage *image = [UIImage imageNamed: kReceiptDetailScrollViewBackgroundCornered];
UIImageView *iv = [[UIImageView alloc] initWithImage: image];
iv.contentMode = UIViewContentModeScaleAspectFit;
iv.frame = [self scrollView].bounds;
[[self scrollView] addSubview: iv];
于 2013-05-02T21:01:45.670 回答