ios - 将 IBDesignable 和 IBInspectable 与 UIViewController 一起使用

标签 ios swift uiviewcontroller

我是 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

来源:Live Rendering

一个

关于ios - 将 IBDesignable 和 IBInspectable 与 UIViewController 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32861352/

相关文章:

ios - 对 <UIViewController> 开始/结束外观转换的不平衡调用

ios - 如何防止 UINavigationBar 在 iOS 7 中覆盖 View 顶部?

php - 保护 GET 请求的好方法?

xcode - Swift Xcode 调试自动完成

ios - 如何为 NSAttributedString 的不同部分添加不同的行距?

swift - 创建 Codable 类的实例时,调用中缺少参数 'from' 的参数

android - 即使应用程序未在 Cordova 中运行,如何每 5 分钟获取一次地理定位

ios - 单点触控 : Relational items positioning inside custom UITableViewCell

ios - 从 xib IBOutlets nil 快速加载 UIViewController

iphone - 通过 UIViewController 以编程方式实现 UIView