Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a UIView from NIB

Tags:

ios

uiview

nib

I have created a custom class that subclasses UIView. I want to do my layout in IB, so have set outlets. The problem is how do I initialise my view so that I get it from the NIB? Any help would be greatly appreciated.

like image 433
John S Avatar asked Sep 27 '11 11:09

John S


People also ask

How do I load a nib file in Swift?

In the XIB, I changed the "File's Owner" class to SomeView (in the identity inspector). I created a UIView outlet in SomeView. swift, linking it to the top level view in the XIB file (named it "view" for convenience). I then added other outlets to other controls in the XIB file as needed.

How do I create a custom UI view?

Open Xcode ▸ File ▸ New ▸ File ▸ Cocoa Touch class ▸ Add your class name ▸ Select UIView or subclass of UIView under Subclass of ▸ Select language ▸ Next ▸ Select target ▸ Create the source file under your project directory. Programatically create subviews, layout and design your custom view as per requirement.


1 Answers

Something like this:

UIView *info = [[[NSBundle mainBundle] loadNibNamed:@"InfoWeather" owner:self options:nil] objectAtIndex:0]; 
like image 72
kv0 Avatar answered Nov 07 '22 15:11

kv0