gpt4 book ai didi

ios - 将 UIImageView 置于 UIScrollView 中居中

转载 作者:行者123 更新时间:2023-11-29 03:57:16 27 4
gpt4 key购买 nike

我试图将 UIImageView 置于 ScrollView 的中心。这是我尝试过的代码,但没有结果。

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

有人知道这是怎么回事吗?

最佳答案

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

UIImage *image = [UIImage imageNamed: kReceiptDetailScrollViewBackgroundCornered];
UIImageView *iv = [[UIImageView alloc] initWithImage: image];
iv.contentMode = UIViewContentModeScaleAspectFit;
iv.frame = [self scrollView].bounds;
[[self scrollView] addSubview: iv];

关于ios - 将 UIImageView 置于 UIScrollView 中居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16347099/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com