iOS development--Xib associated Custom View

Source: Internet
Author: User

Use a custom view under Xib, because many times it might be fortunate to have a view, and then populate the view with controls, but you need to rewrite a lot of useless

Code, and very easy to make mistakes do not say, but also a good workload, using xib words, minutes to fix a view, words do not say, the steps are as follows:

1, first create a view

2, create a xib

3, the class of "File ' Owner" is inherited as: MyView (that is, the custom created view class)

4, then select, such as: In the fourth step, class inherits as: MyView,

5, then, you can happily drag the control on the xib and drag it into the. h file:

6, note that at this time, you must be in the "File's Owner" Inside, the Postcode attribute chat table connection point off, here can not exist such a connection,

7, for example, in the view to connect the connection, you can

8, then load the controller inside, the code is as follows:

Nsarray *nibview =  [[NSBundle Mainbundle] loadnibnamed:@ "xib name "*backview = [Nibview Objectatindex:0= frame;[ Self Addsubview:backview];

Finally, in the controller to write what you want to do, call the time, with the local instantiation of the MyView directly invoke the control, you can!

Example code:

// add push-to-flow trigger button    [_hview.actionbtn settitle:@ " push stream end/play end "  forstate:uicontrolstatenormal];    [_hview.actionbtn settitle: @" Pause Playback " forstate:uicontrolstateselected];        [_hview.actionbtn addtarget:self Action: @selector (Actionbutton:) forcontrolevents:uicontroleventtouchupinside];         // Add play-side trigger button    [_hview.playbtn addtarget:self Action: @selector (Playclick:) Forcontrolevents:uicontroleventtouchupinside];

iOS development--Xib associated Custom View

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.