对于不同的控件状态和使用分数大小,我对 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)
点击按钮后标题不应向右移动。我错过了什么吗?
突出显示状态后
突出显示状态之前
最佳答案
也许您可以在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/