views:

315

answers:

1

How can I add UISwitch(toggle switch) to UIToolBar without using InterfaceBuilder ? It is not a system item, so I could not use

UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                                             target:self
                                                                             action:@selector(pressButton1:)];

How can I add the toggle switch in same way ?
Thank You.

+1  A: 

Just use -initWithCustomView: with your switch as that custom view.

KennyTM
I got it KennyTM. Thank You.
srikanth rongali
But, I cannot set it to user enabled. Should I add code for it to be toggled when touched ?
srikanth rongali
@srikanth: I guess so. The view of the bar button item itself is also a button, which may hijack the touch. You can set the `target` and `action` properties of the bar button item though.
KennyTM
Sorry, for my slow learning. But, I saw this following method. It do not have target and action like remaining methods.- (id)initWithCustomView:(UIView *)customView;
srikanth rongali
Sorry, I did not check well. It is toggling. It is working. I need to to add selectors for on and off conditions. Thank you.
srikanth rongali