Vis*_*ani 20 xcode ios swift ibdesignable ibinspectable
我有创建IBDesignable和IBInspectable自定义类,为视图提供阴影和角半径
但是当我分配Designable类时view,我得到了Designable Build Failed
这是我的代码
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
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我得到的
Ran*_*man 47
对我来说,当我在盘旋时InterfaceBuilder Designables: Build Failed,它会发出一条错误信息
找不到声明的任何源文件或...
所以,我得到了一个线索,就像Xcode无法索引我的自定义UIView类文件所以我做的是我只是退出Xcode并重新启动它然后它已经索引我的自定义Swift类文件,InterfaceBuilder能够正确找到它.
首先尝试一下,然后转到其他选项!
我也偶然发现了这个问题,并有两个可能有用的建议:
#if targetEnvironment(simulator)块内定义了一些类和函数以至少通过构建。就我而言,我的故事板中的设计工作正常,直到我在视图中删除了一些不再需要我的用户界面的标签.
在构建日志或DiagnosticReport文件夹中没有有用的消息.
我的修复是删除DerivedData文件夹(XCode"重启")并重建项目.神奇地,故事板再次显示我的自定义旋钮!:-)
失败是因为的变量IBInspectable在其他人的IBDesignable课堂中使用
以下步骤解决了该问题:
| 归档时间: |
|
| 查看次数: |
12260 次 |
| 最近记录: |