0

I have a problem with ASButtonNode and attributedTitle for different control states and using fractional size. The title becomes shifted to the left.

I behaved correctly if I use a point size for the button.

I am running 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)

The title should not get shifted to the right after tapping the button. Am I missing something?

After highlight state

enter image description here

Before highlight state

enter image description here

Mayur Karmur
  • 2,119
  • 14
  • 35

1 Answers1

0

maybe you can specify the alignment onparagraphStyle

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)

you can create 2 attributedString for each state than set it for respective state

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

Happy Texturing

Wendy Liga
  • 634
  • 5
  • 12