Xib link Xib1. Direct loading of UIView in Xib
Create a view1.xib, set a background color, add a logo uilabel, so you know which view is the view. You can add meaning to this view subview, I just explain the principle, so there is no subview. In the end my View1 such as:
Since View1 will be placed on other view as Subview, so here size is freeform, Status bar is: None.
Put the following code in the Viewdidload:
&1 This line of code is to load the view1.xib, and then save the UIView in Xib to the views, because we only dragged a view in xib, so here lastobject return to this view instance, This loads the UIView in the Xib. This uiview is then addsubview to other view, the effect of the operation
2. Establishing a variable association through the owner
First we create a Iboutlet property for Viewcontroller:
In File's owner, we set it to viewcontroller so that we can associate with the instance variable _referencedview.
Next, in Viewdidload, add the following code below the code you just added:
It's a bit like the code in//1, except that the Owner property is self. This way, after loadnibnamed, the variable _referencedview associated with it is instantiated, and you will see the effect of running the program:
3.Class Owner establishes Variable Association
In fact, this principle is the same as above 2, but here we specifically define a class to act as the owner of the Xib, to all the needs of the relationship view can be declared in this owner, so as to facilitate code management and maintenance.
Here we declare a nsobject subclass Fileowner, and then declare the associated variable of Iboutlet in Fileonwer:
@property (nonatomicweakIBOutletUIView *view;
Similarly, create a view3.xib, File ' s owner, set to Fileowner, and establish a view association:
Next, add the following code at the end of the viewdidload:
4. Introduction of UIView Category
For code simplicity, we add a UIView category method
Where Fileowner's class method:
This makes it easier to load xib code.
Similarly, we create a view4.xib, the File's owner is set to Fileowner, and the View Association is established:
Then add the code at the end of the viewdidload:
5. Customizing the UIView class
On the basis of 4Category, we then introduce the custom UIView class and associate it with it in the xib. First we create a UIView word class UIView5.
Next, we create a view5.xib, the File's owner is set to Fileowner, and the View Association is established:
Then add a UIView to the category method:
Add code at Viewdidload Tail:
6. Set Onwer to Uiviewcontroller
First, we create a view6.xib, File ' s owner, set to Uiviewcontroller. This Uiviewcontroller view property is associated with the UIView in our Xib
Then add the code in the Viewdidload:
Said so much, it is time to do a summary, in fact, it is two methods, one is no file ' s Onwer directly loaded xib in UIView, and the second is through the file ' s onwer associated variable load xib uiview. Then there are some category offers simple interfaces. You can savor the content described above.
You can see my source of Uiview+ext in the category method also provides a method: + (ID) Loadfromnibnoowner; it should be a combination of method 5 and Method 1, I will not elaborate here. Are all evolved from the above two basic methods.
Have you ever thought of link other xib in xib? It's a pity that Apple doesn't support this feature. But we can do this with a little bit of skill. And I'll introduce you briefly.
First of all, the principle of loading xib uiview, if this uiview is a custom UIView (that is, xib is associated with the UIView sub-class), such as:
7.xib Link Xib
This will trigger some methods when the view is loaded, such as:
- (id)initWithCoder:(NSCoder *)aDecoder- (id)awakeAfterUsingCoder:(NSCoder*)aDecoder
We'll do some articles here, and here we'll use the method described earlier to load the UI instance in the desired xib to replace the original returned instance.
First I wrote a UIView class Subview, the code is easy to understand:
To create a embeddedview.xib, we want to link this embeddedview.xib directly in other xib, and we need to create a Subview class Embeddedview.
My xib message is this:
When everything is ready, run:
End
Xib can quickly deployment UI, can improve the speed of development oh.
Multi-Storyboard of iOS development-interrelated addresses:
http://blog.csdn.net/BaiHuaXiu123/article/details/51344871
Multiple xib of iOS development are interrelated