Errors Using Custom UITextField Subclass in Interface Builder

I'm having trouble trying to get a subclass of UITextField to display correctly in Interface Builder using IBDesignable . The subclass is quite simple, it allows the user to define inserts for placing text in a 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 appear fine in IB, but when I try to update one of the values, Xcode creates a project and spits out the following two warnings:

 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 create and run in the simulator just fine, and when I make a presentation, it will display as I expect. It is simple, when I try to do it in IB, that I am going to confront this problem. Other examples that I saw for creating interactive user presentations in Interface Builder seem as simple as mine and work without problems. Is there any step that I am missing, or what am I trying to do, just not going to work?

+5
source share
1 answer

You need to nest your class initializers 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

0
source

Source: https://habr.com/ru/post/1205134/


All Articles