Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XIB files vs. defining layout in code in iPhone

Aside from the WYSIWYG editor, what are the advantages of using XIB/NIB files over defining the layout in code in iPhone/iPad/iOS?

While I don't find XIB files much useful, many iOS developers do, which makes me suspect I might not know their benefits or how to use them properly.

like image 309
hpique Avatar asked Oct 10 '10 05:10

hpique


2 Answers

Defining things in Interface Builder makes them much easier to adjust later. Also, doing interface elements in code can lead to a lot of code bloat, for setting things like exact placement, font, color, etc.

The main advantage using code directly gives you is speed. But it's usually better to start in IB and then see what might need speeding up.

Table cells are one of the main areas where you might consider drawing elements in code for speed.

like image 39
Kendall Helmstetter Gelner Avatar answered Oct 07 '22 14:10

Kendall Helmstetter Gelner


  1. Easier maintenance. More often than not, clients require last minute changes like changing the logo or changing colors or realigning something or some such. Much easier to change it in a xib file and see/show the results immediately
  2. Decoupling. It forces you to write nicely decoupled code right from the offset, which again means easier maintenance.
like image 181
Vaayu Avatar answered Oct 07 '22 13:10

Vaayu