开发者

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
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜