5
我在試圖讓UITextField
的子類在Interface Builder中與IBDesignable
正確呈現時出現問題。子類很簡單,它允許用戶爲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中呈現它時,我正在談論這個問題。我在界面生成器中看到的用於製作交互式自定義視圖的其他示例看起來就像我的一樣簡單,並且運行沒有問題。有沒有我失蹤的一個步驟,或者是我正在嘗試幹什麼而不去工作?