Ios 在Interface Builder中呈现自定义UITextField子类时出错
我在尝试使用Ios 在Interface Builder中呈现自定义UITextField子类时出错,ios,swift,interface-builder,Ios,Swift,Interface Builder,我在尝试使用IBDesignable在Interface Builder中正确呈现UITextField的子类时遇到问题。子类非常简单,它允许用户为UITextField中的文本位置定义插入。代码如下: import Foundation @IBDesignable public class CLYInsetTextField: UITextField { @IBInspectable public var topInset: CGFloat = 0 { didSet
IBDesignable
在Interface Builder中正确呈现UITextField
的子类时遇到问题。子类非常简单,它允许用户为UITextField
中的文本位置定义插入。代码如下:
import Foundation
@IBDesignable public class CLYInsetTextField: UITextField {
@IBInspectable public var topInset: CGFloat = 0 {
didSet {
self.setNeedsDisplay()
}
}
@IBInspectable public var leftInset: CGFloat = 0 {
didSet {
self.setNeedsDisplay()
}
}
@IBInspectable public var bottomInset: CGFloat = 0 {
didSet {
self.setNeedsDisplay()
}
}
@IBInspectable public var rightInset: CGFloat = 0 {
didSet {
self.setNeedsDisplay()
}
}
override public func textRectForBounds(bounds: CGRect) -> CGRect {
return UIEdgeInsetsInsetRect(bounds, UIEdgeInsetsMake(topInset, leftInset, bottomInset, rightInset))
}
override public func editingRectForBounds(bounds: CGRect) -> CGRect {
return UIEdgeInsetsInsetRect(bounds, UIEdgeInsetsMake(topInset, leftInset, bottomInset, rightInset))
}
}
在故事板中使用此类时,属性在IB中显示得非常好,但当我尝试更新其中一个值时,Xcode构建项目并发出以下两个警告:
error: IB Designables: Failed to update auto layout status: dlopen([APP_NAME].app, 1): no suitable image found. Did find:
[APP_NAME].app: can't map unslidable segment __TEXT to 0x100000000 with size 0x7EB000
error: IB Designables: Failed to render instance of CLYInsetTextField: dlopen([APP_NAME].app, 1): no suitable image found. Did find:
[APP_NAME].app: can't map unslidable segment __TEXT to 0x100000000 with size 0x7EB000
我可以在模拟器中很好地构建和运行,当我这样做的时候,视图会按照我的预期呈现。当我试图在IB中呈现它时,我遇到了这个问题。我所看到的在Interface Builder中创建交互式自定义视图的其他示例似乎和我的一样简单,运行起来没有问题。是否有一个步骤我遗漏了,或者我正在尝试做的只是不起作用?您需要在
#if !TARGET_INTERFACE_BUILDER ... #endif
请参阅以获取示例