我是 iOS 开发新手。我正在使用 swift,我想以编程方式设计我的 View ,但我想使用 IBDesigner 和 IBInspectable 来加快我的设计过程。
现在我有一个带有各种按钮和标签的 View Controller 。这是我的代码片段:
@IBDesignable class LandingView: UIViewController, LandingViewProtocol {
@IBInspectable lazy var backButton: UIButton = {
var button = UIButton()
button.backgroundColor = Styles.BUTTON_COLOR
return button
}()
@IBInspectable lazy var caption: UILabel = UILabel()
}
我现在的问题是如何将界面生成器与 IBDesignable 和 IBInspectable 一起使用?我需要添加 .xib 吗?我看到其他一些问题提到我需要使用 Playground ,但我试图避免使用它,我基本上想知道是否可以查看我的整个 View Controller ?
谢谢,
最佳答案
您不能将 IBDesignable 与另一个不是从 UIView 或 NSView 继承的类一起使用。查看 Apple 关于 IBDesignable 的指南:
You can use two different attributes—@IBDesignable and @IBInspectable—to enable live, interactive custom view design in Interface Builder. When you create a custom view that inherits from the UIView class or the NSView class, you can add the @IBDesignable attribute just before the class declaration
一个
关于ios - 将 IBDesignable 和 IBInspectable 与 UIViewController 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32861352/