如何在 AsyncDisplayKit ASButtonNode 上设置标题?
How do I set the title on an AsyncDisplayKit ASButtonNode?
我可以这样设置正常状态的标题:
let buttonTitle = NSAttributedString(string: "Book", attributes: attributes)
buttonNode.titleNode.attributedText = buttonTitle
但是,这不会为按钮的禁用状态设置标题。为此,我尝试添加以下内容:
buttonNode.setAttributedTitle(buttonTitle, for: .disabled)
然而,这会移除正常状态的图块。没有ASControlState.normal
.
如何将按钮的标题设置为在所有状态下都相同?
可以通过为 ASControlState 设置一个空数组来为所有状态设置按钮标题:
let buttonTitle = NSAttributedString(string: "Book", attributes: attributes)
buttonNode.setAttributedTitle(buttonTitle, for: [])
fileprivate var noteButtonNode : ASButtonNode = ASButtonNode()
let attributedTitle : NSAttributedString = NSAttributedString(
string: "Book",
attributes: [
NSFontAttributeName: UIFont.init(name: Fonts.Your_font, size: 16)!,
NSForegroundColorAttributeName: Colors.Your_Color
])
noteButtonNode.setAttributedTitle(attributedTitle, for: ASControlState())
我可以这样设置正常状态的标题:
let buttonTitle = NSAttributedString(string: "Book", attributes: attributes)
buttonNode.titleNode.attributedText = buttonTitle
但是,这不会为按钮的禁用状态设置标题。为此,我尝试添加以下内容:
buttonNode.setAttributedTitle(buttonTitle, for: .disabled)
然而,这会移除正常状态的图块。没有ASControlState.normal
.
如何将按钮的标题设置为在所有状态下都相同?
可以通过为 ASControlState 设置一个空数组来为所有状态设置按钮标题:
let buttonTitle = NSAttributedString(string: "Book", attributes: attributes)
buttonNode.setAttributedTitle(buttonTitle, for: [])
fileprivate var noteButtonNode : ASButtonNode = ASButtonNode()
let attributedTitle : NSAttributedString = NSAttributedString(
string: "Book",
attributes: [
NSFontAttributeName: UIFont.init(name: Fonts.Your_font, size: 16)!,
NSForegroundColorAttributeName: Colors.Your_Color
])
noteButtonNode.setAttributedTitle(attributedTitle, for: ASControlState())