Objective-C
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = CGRectMake(0,40,40); self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn]; [btn setTitle:@"返回" forState:UIControlStateNormal]; [btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
Swift 版本
func createRightBarButtonItem() { buttonRight = UIButton.init(type: UIButtonType.Custom) buttonRight.frame = CGRectMake(0,40) self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: buttonRight) buttonRight.setTitle("Edit",forState: UIControlState.Normal) buttonRight.addTarget(self,action: Selector("jion:"),forControlEvents: UIControlEvents.TouchUpInside) }