How to use custom view in Interface Builder ?

Discussion in 'iOS Programming' started by namanhams, Jun 22, 2009.

  1. namanhams macrumors regular

    Jun 3, 2009

    I've define a custom UIView in a NIB file. I can use it programmatically by loading from NIB file. My question is : is there any way i can use my custom view in IB ? It would be easier to layout everything by IB than by hard coding.
  2. BlackWolf macrumors regular

    Apr 9, 2009
    not gettings it ... if you have your custom view in a NIB file, then you just open that and it goes straight to interface builder, doesn't it?
  3. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    Unfortunately no. For Mac apps it is possible to write a plugin that allows you to edit custom views directly in IB. This isn't available for iPhone apps at this time.
  4. BlackWolf macrumors regular

    Apr 9, 2009
    you can create a view and then tell it that it is a custom view.

    so for example, you write a custom UIView subclass called "MyView". then you create a view in IB and then you can tell it that it is a "MyView" instead of a "UIView".

    that works, if that is what you want. it can be done in IB, by selecting the view, then going to the "View Identity" window (info-button in the view's properties window) and then just enter your custom classname in "Class Identity"
  5. namanhams thread starter macrumors regular

    Jun 3, 2009
    @BlackWolf : yes i do this way. But actually it's still a bit inconvenient, since it's not visual at all. I can just change the identity to my custom class, but the custom view still appears as a white rectangle, and i have to manually change the size. Let's say later i change the size of my custom view, then i also need to change everywhere i use it.
    But i think it's the only way.
    Anw, thanks all for your replies.
  6. BlackWolf macrumors regular

    Apr 9, 2009
    aaah, i see what you mean.
    yeah, that's true.

    but if you are following the logic completly, you should change the size in IB and not programatically. of course, sometimes that's maybe not what you want, but if I create a view in interface builder I do as much as possible in IB, so if for example I change the size of the view I don't need to do anything in xcode.

Share This Page