我创建了IBDesignable和IBInspectable自定义类,以便为视图提供阴影和角半径。
但是,当我将Designable类分配给view时,可设计构建失败
这是我的密码
import Foundation
import UIKit
@IBDesignable
class DesignableView: UIView {
}
@IBDesignable
class DesignableButton: UIButton {
}
@IBDesignable
class DesignableLabel: UILabel {
}
@IBDesignable
class DesignableTableView: UITableView {
}
extension UIView {
@IBInspectable
var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set {
layer.cornerRadius = newValue
}
}
@IBInspectable
var borderWidth: CGFloat {
get {
return layer.borderWidth
}
set {
layer.borderWidth = newValue
}
}
@IBInspectable
var borderColor: UIColor? {
get {
if let color = layer.borderColor {
return UIColor(cgColor: color)
}
return nil
}
set {
if let color = newValue {
layer.borderColor = color.cgColor
} else {
layer.borderColor = nil
}
}
}
@IBInspectable
var shadowRadius: CGFloat {
get {
return layer.shadowRadius
}
set {
layer.shadowRadius = newValue
}
}
@IBInspectable
var shadowOpacity: Float {
get {
return layer.shadowOpacity
}
set {
layer.shadowOpacity = newValue
}
}
@IBInspectable
var shadowOffset: CGSize {
get {
return layer.shadowOffset
}
set {
layer.shadowOffset = newValue
}
}
@IBInspectable
var shadowColor: UIColor? {
get {
if let color = layer.shadowColor {
return UIColor(cgColor: color)
}
return nil
}
set {
if let color = newValue {
layer.shadowColor = color.cgColor
} else {
layer.shadowColor = nil
}
}
}
}这就是我得到的

发布于 2017-12-22 10:34:42
它失败了,因为IBInspectable的变量在其他人的IBDesignable类中使用
以下步骤解决了这一问题:
发布于 2018-06-27 18:21:39
第一次尝试: IBDesignable构建失败
对我来说,当我在InterfaceBuilder Designables: Build Failed上徘徊时,它给出了一条错误消息,上面写着
无法找到声明的任何源文件或..。
所以,我得到的线索是Xcode无法索引我的自定义UIView类文件,所以我只是退出Xcode并重新启动它,然后它已经索引了我的自定义Swift类文件,InterfaceBuilder能够正确地找到它。
首先,尝试一下,然后选择其他选项!
发布于 2018-03-17 01:08:21
在我的例子中,可设计性在我的故事板中正常工作,直到我删除了视图中的一些标签,这些标签对我的用户界面不再是必要的。
在构建日志或DiagnosticReport文件夹中都没有有用的消息。
我的修复方法是删除DerivedData文件夹( Xcode "reboot")并重新构建项目。神奇的是,故事板再次显示了我的定制旋钮!:-)
https://stackoverflow.com/questions/47936991
复制相似问题