When writing Cocoa apps, I do the majority of the user interface layout programmatically. For example:
NSRect popUpFrame = NSMakeRect(10, 10, 100, kDefaultPopUpButtonHeight);
NSPopUpButton * popUp = [[NSPopUpButton alloc] initWithFrame:popUpFrame];
//...
My question is about that kDefaultPopUpButtonHeight
constant. I currently maintain a source file full of such constants, and I fill in the proper sizes manually. I am able to determine the correct sizes by dropping a new control into a blank view in Interface Builder and then checking its properties to see what size IB gives it.
There must be a better way. Is it possible to access these values at runtime? Ideally, I would expect every NSControl
to have a class method something like: +(NSSize)defaultSize
, or, for controls like NSButton
that have different default sizes depending on the particular button style used, something like +(NSSize)defaultSizeForButtonStyle:(NSButtonStyle)buttonStyle
.
Apple's Human Interface Guidelines has information about control layout and the spacing between controls, but it doesn't say anything about the proper sizes for individual controls.