读书人

Custom your view and load in code.

发布时间: 2013-03-25 15:43:04 作者: rapoo

Custom your view and load in code. It's difference viewcontrolller.
NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"MyCustomView" owner:self options:nil];UIView *mainView = [subviewArray objectAtIndex:0];[self addSubview:mainView];

?Remember, if you are initializing an object from a nib, it calls?- (id)initWithCoder:(NSCoder *)aDecoder?to initialize, so you'll have to override that if you are creating the MyCustomView object within the nib. If you're just doing it with?initWithFrame:, then just override that and add the code above. Also, in your nib, make sure you have one top-level UIView, and place all other elements within that (that makes sure that your subviewArray only has one entry).

?

This will load the views from the nib and add them to the object, and should do the trick.


Conversation

?

?

Just do mainView.frame = newFrame. So, if you want the IB view's frame to take up the entire MyCustomView frame, do "mainView.frame = self.bounds".??Ned?

------------------------------------------------------------------------------------------

?

?

读书人网 >移动开发

热点推荐