我正在尝试设置一个导航按钮,使其显示为红色和半粗体。我设法更改了颜色,但在将其更改为半粗体时遇到了困难:
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Sign Up", style: .plain, target: self, action: #selector(signIn))
navigationItem.rightBarButtonItem?.tintColor = .red
UIBarItem.appearance().setTitleTextAttributes(
[
NSAttributedString.Key.font: UIFont.systemFont(ofSize: 12, weight: .semibold)
],
for: .normal)我首先尝试了rightBarButtonItem.appearance,但这似乎不是一个选择。
我正在使用Swift 4.2。
发布于 2019-10-12 02:11:23
可以将style属性设置为.done以使UIBarButtonItem变为粗体。这将一直有效,直到苹果在新版本的iOS中改变done按钮的外观。
navigationItem.rightBarButtonItem?.style = .done发布于 2019-10-12 02:23:27
要拥有完全自定义的栏按钮外观,您可以使用带有自定义视图的栏按钮项,如下所示
let doneButton: UIButton = UIButton (type: UIButton.ButtonType.custom)
doneButton.setTitle("Done", for: .normal)
doneButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 14)
doneButton.setTitleColor(.blue, for: .normal)
doneButton.addTarget(self, action: #selector(self.doneBarButtonTapped(sender:)), for: UIControl.Event.touchUpInside)
doneButton.frame = CGRect(x: 0, y: 0, width: 30, height: 30)
let barButton = UIBarButtonItem(customView: doneButton)
navigationItem.rightBarButtonItem = barButtonhttps://stackoverflow.com/questions/58346376
复制相似问题