I want to create UIView commonly. And use that view in all the view controllers. How can create the UIView sub class with xib and use in all the view controllers? Thanks in advance.
Create a XIB FileRight click on the portion of the screen where your project's files are (view controller, storyboard, etc), and choose new file . Xcode will prompt you for which file type you'd like to create. Choose the View option under the user interface menu.
Create new “View” file from the User Interface menu. This will be your xib that represents a person in your app (let's say it's a dating app). Call it “PersonXIB” (or whatever you want). You're going to see what looks very much like a single view storyboard file with a blank view.
File -> New -> File -> Cocoa Touch -> Objective C-class -> Subclass of Target Class Type
(UIView on your case)xib
for it: File > New > User Interface > View
(name your xib)xib
on the Interface Builder
.Identity Inspector
. Your custom xib will be linked with your custom class.Let me know if you need further detail.
A UIView subclass first of all must consist of some code defining it, regardless of how you're going to use this view. After you create this class, in order to use it you only need to define the class name in the Interface Builder. Select the UIView you added and change it's class name in the object inspector.
Keep in mind that new properties or functionality that you are adding to this UIView will not be accessible by editing the xib, but only by code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With