簡體   English   中英

如何在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())

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM