UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:@"测试" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
button.titleLabel.font = [UIFont systemFontOfSize:17.];
[button addTarget:self action:@selector(rightTitleButtonClick:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
模拟器测试:
iPhone X(11.4):正常显示
iPhone 6s(9.3):不显示
建议解决办法:
1.
button.frame = CGRectMake(0, 0, 64., 20.);
2.
[button sizeToFit];