简体   繁体   English

为iPhone和iPad构建应用程序

[英]Building app for iPhone and iPad

Can any one suggest how I can build Universal app for iPad as well iPhone. 任何人都可以建议如何构建适用于iPad的通用应用程序以及iPhone。 What all things I should take care of ? 我要照顾什么? How to take care of resource images used ? 如何处理使用的资源图像 Is it possible to have same code base should work for iPad as well iPhone. 是否可以使用相同的代码库适用于iPad和iPhone。

In the Target->Project->getInfo->Build->target family-> select iPhone/iPad Target->Project->getInfo->Build->target family-> select iPhone/iPad

And make the conditions everywhere whereever you set frame and also the resolution of the image required by iPAD is high.. so as per condition check whether its running on iPad or iPhone and based on that set your frame and image. 并且无论您在何处设置框架,并且iPAD所需的图像分辨率都很高,所以条件也是如此。因此,根据条件检查它是否在iPad或iPhone上运行并基于此设置您的框架和图像。

hAPPY cODING... 快乐的编码......

After creating your universal app (see @Suriya's post above) you should figure out in the app delegate whether you have an iPad or iPhone. 创建通用应用程序后(请参阅上面的@Suriya的帖子),您应该在应用程序委托中找出您是否拥有iPad或iPhone。 Here is a simple tutorial to do just that. 是一个简单的教程。

Yes, you will need separate nibs and images for an iPad app. 是的,您需要为iPad应用程序单独的笔尖和图像。 But, no, not all the code has to change. 但是,不,并非所有代码都必须改变。 You can simply use class inheritance. 您可以简单地使用类继承。

Example: 例:

You have a MyTableViewController.h and .m file that work on the iPhone. 你有一个可在iPhone上运行的MyTableViewController.h和.m文件。 This table has a custom cell, MyTableViewCell. 该表有一个自定义单元格MyTableViewCell。 Now you want your iPad app to get the same information, but display a larger table and a larger table cell. 现在您希望您的iPad应用程序获得相同的信息,但显示更大的表格和更大的表格单元格。 You then subclass your iPhone classes like so: MyiPadTableViewController : MyTableViewController and MyiPadTableViewCell : MyTableViewCell . 然后你像这样MyiPadTableViewController : MyTableViewController你的iPhone类: MyiPadTableViewController : MyTableViewControllerMyiPadTableViewCell : MyTableViewCell This way you have access to all of your created functions in the parent class, but you can override how the information is displayed. 这样您就可以访问父类中所有已创建的函数,但可以覆盖信息的显示方式。

If you have a function - (void)doSomething:(id)foo; 如果你有一个函数- (void)doSomething:(id)foo; in your MyTableViewController class, you can use it in your MyiPadTableViewController class without writing any extra code, or override it if necessary. 在MyTableViewController类中,您可以在MyiPadTableViewController类中使用它,而无需编写任何额外的代码,或在必要时覆盖它。 The point is you don't have to change code in two places, so it makes life a lot easier. 关键是你不必在两个地方改变代码,这样可以让生活变得更轻松。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM