How to add a button to UINavigationBar?

后端 未结 7 1770
暖寄归人
暖寄归人 2020-12-02 06:19

How to add a button to UINavigationBar programmatically?

7条回答
  •  無奈伤痛
    2020-12-02 06:55

    The example below will display a button with a title "Contact" on the navigation bar on the right. Its action calls a method named "contact" from the viewcontroller. Without this line the right button is not visible.

        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Contact"
                                                                              style:UIBarButtonItemStylePlain target:self action:@selector(contact:)];;
    

    enter image description here

提交回复
热议问题