0

Is it possibile to load buttons at runtime without using .xib files and connect the buttons to class properties anyway (without drag&drop)?

Lotus
  • 3
  • 1

2 Answers2

1

With the "load without .xib" statement do you mean "instantiate in the code", right? in such case the answer is "yes, of course":


// interface
@property (retain) UIButton *myButtonProperty;

// implementation

UIButton *tmpButton = [UIButton buttonWithType:...];
...
self.myButtonProperty = tmpButton;
viggio24
  • 12,316
  • 5
  • 41
  • 34
  • Is it common practice or everybody is using .xibs? – Lotus Jul 04 '11 at 20:42
  • it is common practice, don't worry; xibs are easy to use and you can prepare a view in short time; I use it 80% of the time. But sometimes, especially for views that can dynamically change, using pure code is easier. Probably writing a code completely without XIBs is not a good idea: you can do it, but you will finish to spend a lot of time in resizing the views and setting properties, while with IB this is immediate. – viggio24 Jul 04 '11 at 20:44
0

Yes, it is. You can create button object and add it to a view. More details can be found here.

Community
  • 1
  • 1
Marcin Świerczyński
  • 2,302
  • 22
  • 32