ios - 不同控制状态的 ASButtonNode attributeTitle

标签 ios swift asyncdisplaykit

对于不同的控件状态和使用分数大小,我对 ASButtonNodeattributedTitle 存在问题。标题向左移动。

如果我对按钮使用磅值,我的行为是正确的。

我正在运行texture/asyncDisplayKit 2.8.1

/* Set title */
testButton.setAttributedTitle(NSAttributedString(string: "NORMAL"), for: .normal)
testButton.setAttributedTitle(NSAttributedString(string: "HIGHLIGHTED"), for: .highlighted)

/* styling */
/** This works
 * testButton.style.width = ASDimensionMake("120pt") 
 **/
testButton.style.width = ASDimensionMake("30%")
testButton.style.height = ASDimensionMake(120)

点击按钮后标题不应向右移动。我错过了什么吗?

突出显示状态后

enter image description here

突出显示状态之前

enter image description here

最佳答案

也许您可以在paragraphStyle上指定alignment

let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .center

let attributes = [ ... your current style,
                  .paragraphStyle: paragraphStyle] as [NSAttributedString.Key: Any]
]

let attributedString = NSAttributedString(string: "your text here", attributes: attributes)

您可以为每个州创建 2 个 attributedString,然后为相应的州设置它

testButton.setAttributedTitle(normalAttributedString, for: .normal)
testButton.setAttributedTitle(highlightedAttributedString, for: .highlight)

快乐的纹理

关于ios - 不同控制状态的 ASButtonNode attributeTitle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56439080/

相关文章:

ios - 如何在没有 NavigationController 的情况下使用 ASTableNode 在 ASViewController 上添加像 Navigationbar 这样的 headerView?

objective-c - 在具有 NSDictionary 定义的程序中迷路 @

ios - swift + 核心数据 : Can not set a Bool on NSManagedObject subclass - Bug?

ios - AsyncDisplayKit ASButtonNode setTitle 不起作用

swift - 使用firebase数据库和存储下载数据时索引超出范围异常

ios - swift,来自 View Controller 的 UIUserNotificationAction 而不是应用程序委托(delegate)

iPhone 3GS +/iPad 1 + 最大硬件音频采样率

ios - 如何在快速使用 Segue 时显示标签栏

ios - 如何根据编辑 textfield1 更新 textfield2?

ios - 让我的简单结构在 Swift 4 中可编码不起作用