gpt4 book ai didi

ios - 图像未显示在 UIImageView 中

转载 作者:行者123 更新时间:2023-11-29 13:15:23 26 4
gpt4 key购买 nike

我已经将 UIImageVIew 添加到我的 View 中,如果我指定要在 IB 中使用的图像,那么它会正确显示,但如果我尝试以编程方式添加图像,那么它不会显示。

我清除了要从 IB 加载的图像并添加了以下代码:

- (void)viewDidLoad
{
[super viewDidLoad];
UIImage* image = [UIImage imageNamed:@"pic1.png"];
UIImageView *iv = [[UIImageView alloc] initWithImage: image];
iv.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
iv.contentMode = UIViewContentModeCenter;
self.slideshowView = iv;
}

self.slideshowView 是连接到 ImageView 的导出。

我可以确认 image 和 iv 在执行时都是非空的。

最佳答案

不是创建新的 UIImageView,而是设置 outlet 的图像属性。这里的问题是您的新 UIImageView 在您的 super View 中没有框架,您正在将导出重新指向您创建的新 ImageView 。

self.slideshowView.image = [UIImage imageNamed:@"pic1.png"];

关于ios - 图像未显示在 UIImageView 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15960541/

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