我想自己绘制背景图像,所以我决定实现一个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()
}
}
我是如何连接的:
答案 0 :(得分:1)
刚刚用
测试import UIKit
class CustomView: UIImageView {
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.backgroundColor = UIColor.redColor()
}
}
按预期工作。您必须有其他一些错误 - 可能是由于Autolayout导致的视图放置和大小调整?测试的一个好方法是在IB中设置颜色并检查是否可以看到它。