iOS 添加导航栏自定义右按钮

UIButton *cancleButton = [UIButton buttonWithType:UIButtonTypeSystem];
[cancleButton setTitle:@"撤销" forState:UIControlStateNormal];
[cancleButton setTitleColor:RED_COLOR forState:UIControlStateNormal];
[cancleButton addTarget:self action:@selector(cancleButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:cancleButton];
rightItem.imageEdgeInsets = UIEdgeInsetsMake(0, -15,0, 0);//设置向左偏移
self.navigationItem.rightBarButtonItem = rightItem;

你可能感兴趣的:(iOS 添加导航栏自定义右按钮)