简体   繁体   English

如何在AsyncDisplayKit ASButtonNode上设置标题?

[英]How do I set the title on an AsyncDisplayKit ASButtonNode?

I can set the title for the normal state with this: 我可以这样设置正常状态的标题:

let buttonTitle = NSAttributedString(string: "Book", attributes: attributes)
buttonNode.titleNode.attributedText = buttonTitle

However this doesn't set the title for the button's disabled state. 但是,这不会为按钮的禁用状态设置标题。 To accomplish this, I tried adding the following: 为此,我尝试添加以下内容:

buttonNode.setAttributedTitle(buttonTitle, for: .disabled)

However this then removes the tile for the normal state. 但是,这将删除正常状态下的图块。 There is no ASControlState.normal . 没有ASControlState.normal

How can I set the button's title to be the same in all states? 如何在所有状态下将按钮的标题设置为相同?

The button title can be set for all states by setting an empty array for the ASControlState: 可以通过为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())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM