【发布时间】:2018-09-19 13:50:15
【问题描述】:
我创建了一个自定义视图,但是当我将它添加到情节提要屏幕时,它不显示内容(启动应用程序时,所有内容都会显示)。 在看到lesson 之后,我意识到我需要在类前面添加“IBDesignable”,但这并没有帮助,我在 View 中看不到内容。而且,现在Xcode会报渲染错误:
"IB Designables: Failed to render and update auto layout status for Test1ViewController (R7h-8I-M68): The agent threw an exception.".
请教你的意见
import UIKit
@IBDesignable class ww: UIView {
var view: UIView!
@IBOutlet weak var yellowLine: UIView!
override init(frame: CGRect) {
super.init(frame: frame)
self.commonInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.commonInit()
}
func commonInit()
{
let view = Bundle.main.loadNibNamed("ww", owner: self, options: nil)?.first as! UIView
view.frame = self.bounds
view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.addSubview(view)
}
}
附: - 我无法添加图片,因为我的声誉
【问题讨论】:
-
请分享您的试用代码?
-
你可以查看这个 StackOverflow 问题。 stackoverflow.com/questions/39732312/…