ios - 以编程方式设置 IBInspectable

标签 ios swift storyboard ibinspectable

我想根据我获得的互联网信息设置不同的 IBInspectable 项目。例如,我有用于绿色、红色和橙色圆圈的 IBInspectables。如果请求说绿色,我想将 isGreen inspectable 设置为 Yes,其他设置为 no。其他两个也一样。 可以看到IBInspectables here .我知道我可以用我放在那里的代码来做到这一点,但是有没有办法以编程方式切换它们?

最佳答案

任何 IBInspectable 都只是编码为在 IB 中可见的属性。所以如果你有这个:

@IBInspectable var isGreen:Bool? {
    didSet {
        // code to color circle?
    }
}

你可以这样做:

self.isGreen = true

关于ios - 以编程方式设置 IBInspectable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40948264/

相关文章:

ios - UINavigationController:在 iPad 上呈现 View Controller ,同时关闭另一个 Controller

ios - UICollectionView 和 Selected Cell 在滚动时失去选择

ios - AudioKit(仍然)缺少用于对音频文件进行排序的时钟

c# - 通过 Storyboard更改时数据绑定(bind)不更新?

iphone - Xcode Copy Bundle Resources找不到文件

ios - Swift函数错误: 'Float' is not convertible to 'Void'

ios - 无法按下具有拐角半径的 UIView 下方的 UIButton

swift - 如何在 iOS 10 的 iMessage 应用程序中发送带有图像和标题的音频文件?

ios - 如何从我的 iPhone 向 Apple 电视应用程序发送数据

ios - 具有多个 ViewController 的 SplitView - Storyboard - iOS