简体   繁体   English

在Interface Builder中呈现自定义UITextField子类的错误

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

I'm having issues trying to get a subclass of UITextField to render properly in Interface Builder with IBDesignable . 我在尝试使用IBDesignable在Interface Builder中正确渲染UITextField的子类时遇到问题。 The subclass is pretty simple, it allows the user to define insets for the text placement in a UITextField . 子类非常简单,它允许用户为UITextField的文本放置定义插入。 The code is as follows: 代码如下:

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))
    }
}

When using this class in a storyboard, the properties show up in IB perfectly fine, but when I try to update one of the values, Xcode builds the project and spits out the following two warnings: 在故事板中使用此类时,属性在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

I can build and run in the simulator just fine, and when I do the view is rendered as I expect it to. 我可以在模拟器中构建和运行得很好,当我这样做时,视图会像我期望的那样呈现。 It's just when I try to render it in IB that I am coming up against this issue. 只是当我尝试在IB中呈现它时,我正在反对这个问题。 Other examples I have seen for making interactive custom views in Interface Builder seem to be just as simple as mine and run without problems. 我在Interface Builder中看到的用于制作交互式自定义视图的其他示例似乎就像我的一样简单并且运行没有问题。 Is there a step I am missing, or is what I am trying to do simply not going to work? 是否有一个我缺少的步骤,或者我正在努力做什么根本不去工作?

You need to enclose your class initialisers in 您需要将类初始化程序括起来

#if !TARGET_INTERFACE_BUILDER ... #endif

See http://digitalleaves.com/blog/2015/02/tutorial-building-your-own-custom-ibdesignable-view-a-uitextview-with-placeholder/ for an example 有关示例,请参见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.

相关问题 没有接口生成器的自定义 UITabBar 子类 - Custom UITabBar subclass without Interface Builder 为什么我的IBDesignable UIButton子类未在Interface Builder中呈现? - Why Is My IBDesignable UIButton Subclass Not Rendering In Interface Builder? UITextView的接口构建器和子类 - Interface builder and subclass of UITextView 在Interface Builder中连接子类的自定义委托以进行控制 - Connect subclass's custom delegate for control in Interface Builder UIView子类:检测在接口构建器中设置的UIView的大小,该生成器使用所述UIView子类作为自定义类 - UIView Subclass: Detect the size of a UIView set up in Interface Builder which uses said UIView subclass as a custom class UITapGestureRecognizer不适用于UITextField的自定义子类 - UITapGestureRecognizer not working for custom subclass of UITextField 自定义元素的子层未在模拟器中呈现,在界面生成器中呈现 - Sublayer of custom element not rendering in simulator, renders in interface builder 为什么我的自定义UITextField在Interface Builder上与在设备上运行时看起来有所不同? - Why does my custom UITextField look like different at Interface Builder vs in running on device? 将Interface Builder中的UITextField连接到代码中定义的IBOutlet - Connecting UITextField in Interface Builder to IBOutlet defined in code 使用Interface Builder在UITextField上关闭键盘 - Dismiss keyboard on UITextField using Interface Builder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM