views:

1957

answers:

6

I am wondering if I would run into troubles when setting the heights of my views in the neb with fixed values.

Example: The height of the Status Bar is known. It's 20 units. So when making a view that shows an nice interface, what would happen when the user takes a phone call while using the App, and the Status Bar increases in height? Or what if Apple changes the height of the Status Bar, or Tab Bar, some day in future?

Do you always use autoresizing features for your container-view that has all the interface elements inside? What's your pattern?

+4  A: 

I always use a flexible layout that resizes automatically because that allows me to focus on the design and let the computer figure out the math.

[EDIT] My reason is that something is going to change and I don't want to do the math again in this case. Things that can change:

  • Users might select bigger fonts
  • The next generation of the device gets a bigger screen
  • Translators hate it when they have to fit words into pixel-tight spaces
  • An add-on might take up a few pixels on the screen
  • A change in the OS might change the screen size by a few pixels
  • When I'm using predefined icons, their size might change
  • Ultimately, in a flexible application, the user can choose what she wants to see. I don't want her to have to layout the UI.

So if you make your layout static, you'll eventually have to do it again. And again. Until you learn that the only constant in software development is change.

Aaron Digulla
But what do you do if you're using your space precisely? IE if your screen is full of controls, perfectly placed?
Thanks
Something is going to come up. It always does.
Aaron Digulla
+6  A: 

I would steer clear of hard coding values for the heights of the status bar, tool bar, etc into your program. You present some good examples of how these values are dynamic and can change in the future. One other common scenario that you may or may not be supporting is the ability of the user to rotate the iPhone into landscape orientation.

I always try to keep the layout of the subviews of a container flexible. Using the autoresizing feature is a good approach. Your question is a good one and I think its going to make me review my own layout strategy!

Jonathan Arbogast
Thanks! I'd like to know how to test those events when the status bar or tab bar becomes bigger or smaller.
Thanks
Here is one simple method that I use. Just run your application in the simulator and then go to Hardware->Toggle In-Call Status Bar. The Status Bar will grow. Pick the same menu option to get the Status Bar back to its original size.
Jonathan Arbogast
You can use the same menu to also Rotate the device left and right to check out your layout when in a landscape orientation.
Jonathan Arbogast
Thanks! What a great hint! My App looks veeeeeeeeeeeeeeeeery bad ;) lol
Thanks
Another consideration is future proofing what if there is a different screen resolution iphone or ipod touch later. Maybe the app store will be extended to some sort of UMPC tablet or whatever.
PeteT
I hope Apple WILL bring out more devices. But really, if the differences are too big, it makes sense to develop different branches. An App on a 10" screen might not look so good if it was designed to fit in a 2" screen, since an App that's specialy made for that 10" screen just takes better advantage of the device.
Thanks
A: 

Aren't most of these size present in the Apple supplied file "Constants.h"? (I've just noticed that it is part of the UICatalog SDK example).

I think it is very likely that Apple will launch another device sometime which has a larger or smaller screen. So they should be used in conjunction with [UIScreen frame/bounds];

// these are the various screen placement constants used across all the UIViewControllers

// padding for margins
#define kLeftMargin             20.0
#define kTopMargin              20.0
#define kRightMargin            20.0
#define kBottomMargin           20.0
#define kTweenMargin            10.0

// control dimensions
#define kStdButtonWidth        106.0
#define kStdButtonHeight        40.0
#define kSegmentedControlHeight 40.0
#define kPageControlHeight      20.0
#define kPageControlWidth      160.0
#define kSliderHeight            7.0
#define kSwitchButtonWidth      94.0
#define kSwitchButtonHeight     27.0
#define kTextFieldHeight        30.0
#define kSearchBarHeight        40.0
#define kLabelHeight            20.0
#define kProgressIndicatorSize  40.0
#define kToolbarHeight          40.0
#define kUIProgressBarWidth    160.0
#define kUIProgressBarHeight    24.0

// specific font metrics used in our text fields and text views
#define kFontName               @"Arial"
#define kTextFieldFontSize      18.0
#define kTextViewFontSize       18.0

// UITableView row heights
#define kUIRowHeight            50.0
#define kUIRowLabelHeight       22.0

// table view cell content offsets

#define kCellLeftOffset          8.0
#define kCellTopOffset          12.0

Tony

Tony Lambert
I went looking, since I thought this would be an interesting file to look through, and I cannot find any reference to a UIConstants.h file in either The OS X SDK or the iPhone SDK. Am I missing something, or maybe is this file named differently?
mmc
+3  A: 

Well, I'm going out on a limb here, but I think that the idea of hard coding layout dimensions (which, today, on the iPhone, are in pixels) could theoretically get you in trouble (or at least make extra work) in the future.

I'm not so much concerned about them changing the apparent size of the status bar, or the default tab bar, or the navigation bar... I'm worried about the units changing. I'm not a registered OS X developer, but it has long been rumored that Snow Leopard is going to support a resolution independent way of specifying interfaces, not based on pixels.

It won't happen tomorrow, or in 3.0, or maybe even next year, but this idea of a resolution independent interface is going to make it to the iPhone, especially as display size (and more specifically, display resolution) change in the future.

I'm being long winded, but it's not the size of the status bar I'm concerned with changing in the future, it's the size of the device, and the units we use to specify sizes in Cocoa Touch.

mmc
the iPhone HAS already a resolution independent interface. You don't specify pixels. You specify units. In case of iPhone, currently one unit is one pixel. But this may change in the future.
Thanks
Well, I'll be. You're right. Since for the current screen form factor 1 unit = 1 pixel, I had never given it any thought. This will prove to be VERY important when the size or resolution of the device changes.
mmc
Yes, when they will change display size, or more importantly the aspect ratio, then some Apps will run into trouble. But as currently there is only one screen size, I don't worry too much. If they really bring out an iPhone nano then i'll have to work around a little bit ;) but that's why I've choosen iPhone OS rather than Google Android, where you have millions of screen sizes and aspect ratios.
Thanks
+1  A: 

One thing to think about: if the user gets a phone call and then launches the application during the phone call, the status bar's height will change. So it's definitely a necessity to avoid hard-coding in the height of system UI elements.

Jeff Kelley
+1  A: 

Theres a "constants.h" in the UICatalog sample, but it's local to that sample and is clearly just a way for the sample developer to make his/her life easier. It carries with it all the problems mentioned above ... if anything changes the "standard sizes" in the future, this sample stops working properly.

It sucks to have to query other objects to get your placement right, but it's how you ensure things work properly when the environment changes. The expanding "in-call" status bar is a perfect example. If you hard-code 20 "units" to avoid the status bar, your app breaks while in a call. And, that's something you're not likely to notice in the simulator (because, if you thought about it enough to try that option in the simulator, you probably would have thought about it while coding the app!)

BigSprocket
You're so right man. Thanks.
Thanks