簡體   English   中英

在Interface Builder中呈現自定義UITextField子類的錯誤

[英]Errors with rendering custom UITextField subclass in Interface Builder

我在嘗試使用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

有關示例,請參見http://digitalleaves.com/blog/2015/02/tutorial-building-your-own-custom-ibdesignable-view-a-uitextview-with-placeholder/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM