Connect a UILabel in Interface Builder and XCode?

前端 未结 5 1264
梦如初夏
梦如初夏 2020-12-20 15:00

I am trying to do something as simple as add a Label to a View in XCode and IB and I can\'t figure out how to do it. All the samples I find online are for older versions of

5条回答
  •  醉话见心
    2020-12-20 15:38

    Assume that you have a viewController and a xib file which has a UILabel on this. The steps to connection the UiLabel (also the xib file) your viewController are:

    1) In the header file, create UiLabel object and property for it

    IBOutlet UILabel *label;
    
    @Property (Nonatomic, retain) IBOutlet UILabel *label;
    

    and synchthesize it in implement file

    2) Open your xib file in Interface Builder

    Double click on "File's Owner" then select the viewController in dropdownlist of pop-up windows to connect your xib file to controller

    3) right-click on file's owner, on the pop-up dialog:

    • point and drag the plush (+) next to "View" and drop it on View row
    • point and drag the plush (+) next to "label" and drop it on the label on the view

    => now the label and the view on xib file is connected to you controller

提交回复
热议问题