Xib for iPhone and iPad

Deadly 提交于 2019-12-06 05:24:50

问题


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:

  1. MyClass
  2. MyClass_iPhone: MyClass
  3. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!