gpt4 book ai didi

ios - 将 Storyboard UIImageView 更改为具有背景颜色的自己的类

转载 作者:行者123 更新时间:2023-11-29 02:43:12 24 4
gpt4 key购买 nike

我想自己画背景图,所以我决定实现一个UIImageView类,并连接到Storyboard中。作为第一个任务,我只想自己设置图像的背景色,但它从未显示过。图片保持空白。

这就是类:

class FirstBackgroundImage : UIImageView {

required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.backgroundColor = UIColor.redColor()

}

override init() {
super.init()
self.backgroundColor = UIColor.redColor()
}

override required init(image: UIImage!) {
super.init(image: image)
self.backgroundColor = UIColor.redColor()
}

}

这就是我连接它的方式:

uiimageview class

最佳答案

刚刚测试过

import UIKit

class CustomView: UIImageView {

required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.backgroundColor = UIColor.redColor()
}
}

按预期工作。您一定有其他错误 - 也许是由于自动布局导致 View 的放置和大小调整?一个好的测试方法是在 IB 中设置颜色并检查是否可以看到它。

关于ios - 将 Storyboard UIImageView 更改为具有背景颜色的自己的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25483681/

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