0

我对不同的控制状态和使用小数大小有ASButtonNode疑问attributedTitle。标题向左移动。

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

我正在跑步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)

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

高亮状态后

在此处输入图像描述

高亮状态之前

在此处输入图像描述

4

1 回答 1

0

也许你可以指定alignmentonparagraphStyle

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)

您可以attributedString为每个状态创建 2 个,而不是为相应的状态设置它

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

快乐纹理

于 2019-07-20T15:42:24.783 回答