3 ms·
Cocoa doesn't require hundreds of lines to represent a simple object. Here's code to make a button: UIButton *button = [UIButton buttonWithType:UIButtonTy
by neild 16y ago
Cocoa doesn't require hundreds of lines to represent a simple object. Here's code to make a button:
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"Button" forState:UIControlStateNormal];
That's it. Two lines for a basic button.
Of course, if you want to display the button:
button.frame = CGRectMake(10, 10, 80, 20);
[view addSubview:button];
...which is a big part of why Interface Builder is handy, because it saves you from trying to figure out exactly how large you want the button to be and where to put it.
Now, when you put together all the objects in a moderately complicated UI, you will end up with hundreds of lines of code. Some people find it easier to work with this visually in Interface Builder. Others find it easier to manually construct the UI in code. Either method works perfectly well. I generally use a mix of both, depending on the nature of the UI element I'm working with.
- mckoss 16y agoVery helpful. Thanks!
- wallflower 16y ago> Some people find it easier to work with this visually in Interface Builder. All of our designers use IB to layout the UI. It works really well - as they don't have to touch the code and we don't have to touch the layout. Unfortunately, if you are doing any kind of custom animation (think sliding/expanding), IB is useless - you'll have to set the frames in code. In general, IB is great because it helps separate presentation from the code. When I first started out, I hated IB, but I've come to accept the fact that it really does help productivity (when working with designers closely). If you hate IB, consider going Android - there is nothing like IB on Android. All XML and a simple (nothing like IB) layout editor.