iOS Edge learning--xib file First Use

Source: Internet
Author: User

One, Xib and storyboard contrast

In common

1> are used to describe the software interface

2> are edited with the Interface Builder tool.

3> essence is converted into code to create the control

* Different points

1>xib is lightweight and is used to describe the local UI interface

2>storyboard is a heavyweight, a multi-interface for describing the entire software, and the ability to show jump relationships between multiple interfaces

Second, the loading method of Xib

Method 1:

Nsarray *views = [[NSBundle mainbundle] loadnibnamed:@ "xib file name" Owner:nil Options:nil];

Method 2:

uinib *nib = [uinib nibwithnibname:@ "xib filename" bundle:nil];

Nsarray *views = [nib Instantiatewithowner:nil options:nil];

Iii. steps to customize view with Xib

* New custom control class, inherited from UIView

* New Xib file (filename suggestion and view class name match)

    

* Modify the class name of view in Xib

* Package Xib loading process, the steps to read the Xib file are encapsulated in the class, because the Xib file name and the class name, so you can directly get the names of the class to use Nsstringfromclass (self)

1 + (Chaosshopview *) Shopview2{3     Chaosshopview *shopview = [[[ NSBundle Mainbundle] Loadnibnamed:nsstringfromclass (self) owner:nil options:nil] lastobject]; 4     return Shopview; 5 }

* Add model properties, set data to child controls in the set method of model properties

 1  //  2 -( void ) Setshopmodel: (Shopmodel *) Shopmodel  3  4  //  Override set method prerequisites, assign the passed variable to the member variable  Span style= "color: #008080;" >5  _shopmodel = Shopmodel;  6   [_ Viewimage setimage:[uiimage ImageNamed:shopModel.icon];  8  _namelabel.text = Shopmodel.name;  9 } 

* Child control access can be defined in the extension class, with "Off-line" way to implement

iOS Edge learning--xib file First Use

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.