通用iOS应用-UIButton和UITableView大小 [英] Universal iOS app - UIButton and UITableView sizes

查看:72
本文介绍了通用iOS应用-UIButton和UITableView大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用XCode 5.0.2和iOS 7开发我的第一个通用iOS应用程序,并且我对iPhone和iPad(包括Mini)之间的屏幕尺寸差异有一些疑问.

I'm developing my first universal iOS app with XCode 5.0.2 and iOS 7, and I have some questions on the screen size differences between iPhone and iPad (including Mini).

如果应用程序包含具有自定义.png图像的UIButton,那么在为iPad开发时是否需要增加UIButton的大小以及更大的图像?我已经使用iPhone应用程序完成了一半,不使用情节提要,而是使用IB创建NIB.我试图在iPad NIB上使用相同的iPhone UIButton尺寸,但它看起来很小.对于这两个不同的设备,使用更大尺寸的UIButton s和自定义尺寸的png图像文件是正确的方法吗?

If the app contains UIButtons with custom .png images, do I need to increase the size of the UIButtons along with bigger size images when developing for iPad?. I'm already half done with the iPhone app and not using storyboards but using IB to create NIBs. I tried to use the same iPhone UIButton size on the iPad NIB and it looks small. Is this the right approach of having bigger size UIButtons along with custom sized png image files for these two different devices?

UITableViews也有同样的问题.我需要在iPad上安装更大的iPad吗? iPhone在iPad上看起来更小.另外,请注意,我添加了一个新的iPad专用NIB,但是将相同的UITableView控件从iPhone专用NIB复制到了iPad NIB.

The same questions go with UITableViews. Do I need to have bigger ones on the iPad?. The iPhone ones look smaller on the iPad. Also, note that I added a new iPad specific NIB but copied the same UITableView control from the iPhone specific NIB to the iPad NIB.

我还在AppCoda上阅读了本文,在以下情况下使用自定义按钮尺寸我使用XCode 5打开了示例项目.

I also read this article on AppCoda, custom button sizes are used when I opened the sample project with XCode 5.

Another article from Ray Wenderlich's site (although 3 years old) talks about autosizing.

哪种方法最好?或者我需要知道什么?

Which is the best approach or is there anything that I need to know?

推荐答案

1.关于布局:

Autoresizing MasksLayout Constraints(又称Auto Layout)都解决了鉴于这种不同的视图大小会发生什么?"的问题.与您创建的笔尖相比(例如,视图的方向是否改变或在不同的屏幕尺寸上运行).

Both Autoresizing Masks and Layout Constraints (a.k.a. Auto Layout) address the issue of "what happens given this different view size?" compared to the nib you create (i.e. if the orientation of the view changes or if run on a different screen size).

您应该在每个用户界面组件(UIButtonUITableView等)上设置Autoresizing MasksLayout Constraints,以告诉他们应该如何调整它们的大小.

You should set either Autoresizing Masks or Layout Constraints on each of your user interface components (UIButton, UITableView, etc) to tell them how they should be resized.

如果您仅针对iOS 6.0+,则可以使用Layout Constraints(推荐的最新方法来调整大小).但是,如果您更习惯Autoresizing Masks,则仍然可以根据需要使用它们(只需关闭笔尖上的Auto Layout即可).

If you're just targeting iOS 6.0+, you can use Layout Constraints (the latest, recommended way to handle resizing). However, if you're more comfortable with Autoresizing Masks, you can still use them if you prefer (you'll just need to turn off Auto Layout on your nibs to do such).

这是好文章,提供有关Auto Layout的介绍.

Here's a good article from Ray Wenderlich's site for an introduction on Auto Layout.

2.关于背景图片:

如前所述,您正在使用.png图像作为按钮背景,因此应确保包含的图像适用于UIButton的所有可能尺寸(包括retinanon-retina图像).

As you've mentioned that you're using .png images for button backgrounds, you should make sure that you include an image(s) that will work for all of the possible sizes of your UIButtons (including both retina and non-retina images).

理想情况下,您可以设计背景图像以使其可以拉伸,并使用UIImage的方法resizableImageWithCapInsets:resizingMode:为背景图像创建UIImage.

Ideally, you design your background images such that they can be stretched and use UIImage's method resizableImageWithCapInsets:resizingMode: to create UIImage for the background image.

这是有关设计iOS按钮背景的教程

Here's a tutorial on designing iOS button backgrounds that should be helpful too.

看看UIImage(Google it-> Apple的链接经常更改)和resizableImageWithCapInsets:resizingMode:方法的文档,您也可能会受益.

You will likely also benefit from taking a look at the documentation for UIImage (Google it-> Apple's links change too often) and the resizableImageWithCapInsets:resizingMode: method.

这篇关于通用iOS应用-UIButton和UITableView大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆