问题
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).
If the app contains UIButton
s with custom .png
images, do I need to increase the size of the UIButton
s 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 UIButton
s along with custom sized png image files for these two different devices?
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.
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:
1. Regarding 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).
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.
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).
Here's a good article from Ray Wenderlich's site for an introduction on Auto Layout
.
2. Regarding Background Images:
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 UIButton
s (including both retina
and non-retina
images).
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.
Here's a tutorial on designing iOS button backgrounds that should be helpful too.
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.
回答2:
For the images for your buttons you are going to need different sizes for retina versus non-retina. If you decide you want bigger buttons on the iPad, then you will of course need bigger images. For the UITableViews it will depend on what you want to do with them. If you want the UITableViews to fill the full screen, then yes it will have be bigger (though auto layout or layout constraints can handle that for you).
来源:https://stackoverflow.com/questions/20670585/universal-ios-app-uibutton-and-uitableview-sizes