问题
I have a Xib for iPhone and I need a similar view for iPad, only iPad size.
What is the best way of doing this? Can you put both views in the same Xib and somehow specify which one is shown?
Or do I need to be make 2 Xib files and 2 classes?
回答1:
I ended up using 1 class. I set the file owner of both XIB files to this same class.
I just used the name of the XIB file
So I have 2 xibFiles, iPadXib.xib and iPhoneXib.xib
NSString *nibFileName = (iPadVersion) ? @"iPadXib" : @"iPhoneXib";
ViewControllerName *vc = [[ViewControllerName alloc] initWithNibName:nibFileName bundle:nil];
回答2:
Or do I need to be make 2 Xib files and 2 classes?
Actually, use three classes and 2 xibs. Like this:
- MyClass
- MyClass_iPhone: MyClass
- MyClass_iPad: MyClass
And the two xibs. It gives you much more flexibility. Keep the common logic on the MyClass, and sub-class the other two for the iPhone and iPad Version.
回答3:
If you want both iPhone and ipad Create Universal App. Create only One XIB and create all controls only once not need to do it separately. Draw the frame in coding. ie, Create frame separate for both iphone and ipad.
来源:https://stackoverflow.com/questions/13496218/xib-for-iphone-and-ipad