vrg*_*grg 6 fonts uibutton ios
我想将自定义字体设置为UIButton. 我需要以编程方式设置它,因为否则不会应用字体。问题是单击后它会变回内置字体。我究竟做错了什么?
import UIKit
class LoginViewController: UIViewController {
@IBOutlet weak var emailTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
@IBOutlet weak var eyeButton: UIButton!
@IBOutlet weak var loginButton: UIButton!
var iconClick = true
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
override func viewDidLoad() {
super.viewDidLoad()
loginButton.titleLabel?.font = UIFont(name: "Capitana-Bold", size: CGFloat(16))
}
@IBAction func iconAction(sender: AnyObject) {
if (iconClick == true) {
passwordTextField.isSecureTextEntry = false
eyeButton.setImage(UIImage(named: "eye-closed"), for: .normal)
} else {
passwordTextField.isSecureTextEntry = true
eyeButton.setImage(UIImage(named: "eye-open"), for: .normal)
}
iconClick = !iconClick
}
@IBAction func onLoginClicked(_ sender: Any) {
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个 iOS 15 填充按钮。你不能通过说来配置它
loginButton.titleLabel?.font = ...
Run Code Online (Sandbox Code Playgroud)
这在 iOS 14 及之前的版本中是可能的(但错误的),但对于 iOS 15 按钮来说这是不可能的。要以编程方式配置填充按钮,您必须设置其配置对象。
https://developer.apple.com/documentation/uikit/uibutton/configuration
特别是您想要设置按钮配置属性标题。
https://developer.apple.com/documentation/uikit/uibutton/configuration/3750779-attributedtitle
| 归档时间: |
|
| 查看次数: |
1382 次 |
| 最近记录: |