开发者

How can I add UISwitch(toggle switch) to UIToolBar without using InterfaceBuilder

开发者 https://www.devze.com 2022-12-28 02:54 出处:网络
How can I add UISwitch(toggle switch) to UIToolBar without using InterfaceBuilder ? It is not a syst开发者_如何学JAVAem item, so I could not use

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
0

精彩评论

暂无评论...
验证码 换一张
取 消