使用系统设置,在iOS11.4上会出现点击时,文字变大,颜色变为蓝色.所以使用按钮还是靠谱些.
1 2 3
| UIBarButtonItem *allReadItem = [[UIBarButtonItem alloc] initWithTitle:@"全部已读" style:UIBarButtonItemStylePlain target:self action:@selector(allReadItemDidClicked:)]; [allReadItem setTitleTextAttributes:@{NSFontAttributeName : [UIFont pingFangSCWithSize:14], NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#333333"]} forState:UIControlStateNormal]; self.navigationItem.rightBarButtonItem = allReadItem;
|
解决办法使用自定义按钮:
1 2 3 4 5 6 7 8
| UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.titleLabel.font = [UIFont pingFangSCWithSize:14]; [btn setTitle:@"全部已读" forState:UIControlStateNormal]; [btn setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateNormal]; [btn addTarget:self action:@selector(allReadItemDidClicked:) forControlEvents:UIControlEventTouchUpInside]; [btn sizeToFit]; UIBarButtonItem *allReadItem = [[UIBarButtonItem alloc] initWithCustomView:btn]; self.navigationItem.rightBarButtonItem = allReadItem;
|