How can I add UISwitch(toggle switch) to UIToolBar without using InterfaceBuilder
How can I add UISwitch(toggle switch) to UIToolBar without using InterfaceBuilder ? It is not a syst开发者_如何学JAVAem 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.Just use -initWithCustomView:
with your switch as that custom view.
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
精彩评论