mbogh / NibDesignable

Elegant way of enabling IBDesignable on your nib-based views
MIT License
342 stars 74 forks source link

connecting to IBOutlet from a NibDesignable subclass #22

Closed edwardIshaq closed 7 years ago

edwardIshaq commented 8 years ago

First i must say that the NibDesignable class is awesome.

I've created a subclass called LineField which contains a UITextField with a line under it. when I plug in my LineField into my Storyboard, I wanted to be able to connect an IBOutlet on my UIViewController to the LineField's text field. but unfortunately that doesn't seem possible. Is there a way to do that which I'm not aware of ?

@IBDesignable
public class LineField: NibDesignable {

    @IBOutlet weak var textField: UITextField!
    @IBOutlet weak var lineView: UIView!

    @IBInspectable public var lineColor: UIColor = UIColor.lightGrayColor() {
        didSet {
            self.lineView.backgroundColor = lineColor
        }
    }

    override public func awakeFromNib() {
        super.awakeFromNib()
    }

}

My ViewController:

class TextQuestionEditVC: UIViewController {

    @IBOutlet weak var saveButton: UIBarButtonItem!
    @IBOutlet weak var questionLineField: LineField!
    @IBOutlet weak var searchField: UITextField!

}

TLDR: how do i connect my searchField to the LineField->textField ?

mbogh commented 8 years ago

Hi @edwardIshaq, as far as I know this is not possible to connect a sub view/control to an outlet on your view controller.

May I ask why you would want to connect the UITextField from your LineField to the searchField outlet??

edwardIshaq commented 8 years ago

I wanted to be able to work directly and customize the uitextfield directly with having to expose all the standard IBDesignables

Edward Ashak

On Oct 28, 2015, at 12:12 PM, Morten Bøgh notifications@github.com wrote:

Hi @edwardIshaq, as far as I know this is not possible to connect a sub view/control to an outlet on your view controller.

May I ask why you would want to connect the UITextField from your LineField to the searchField outlet??

— Reply to this email directly or view it on GitHub.

IsmailHassanein commented 8 years ago

@edwardIshaq How about the following: Make your textField public

  1. @IBOutlet public var textfield: UITextField!
  2. in your viewController create searchField this way var searchField:UITextField! { return lineField?.textFeild}