Question

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.

Was it helpful?

Solution

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

OTHER TIPS

Here is what I did in my swift app, where I had to switch between two different modes of display.

    let optionSwitch:UISwitch = UISwitch()

    let optionToolButton:UIBarButtonItem = UIBarButtonItem(customView: optionSwitch);
    self.navigationItem.rightBarButtonItem = optionToolButton
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top