【问题标题】:Storyboard UIView background color disappears when assigned @IBDesignable custom class分配 @IBDesignable 自定义类时,Storyboard UIView 背景颜色消失
【发布时间】:2016-02-04 02:51:40
【问题描述】:
重现步骤:
在下面创建类似MyIcon的类;
将 UIView 拖到故事板上(背景为白色);
设置UIView的自定义类为MyIcon;和
背景颜色消失。
MyIcon.swift:
import UIKit
@IBDesignable class MyIcon: UIView {}
请参阅下面的故事板屏幕截图,了解白色背景颜色丢失的证据:
【问题讨论】:
标签:
xcode
swift
uistoryboard
xcode-storyboard
ibdesignable
【解决方案1】:
可能是MyIcon 类中缺少一个init 函数。
@IBDesignable 至少需要这两个函数:
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(frame: CGRect) {
super.init(frame: frame)
}
为确保安全,您还可以查看 /Users/{yourusername}/Library/Logs/DiagnosticReports/ 中的崩溃报告