A sample project for facebookarchive/AsyncDisplayKit#2885。
I just use ASDK soon, found ASTextNode
display abnormal when input with some string contains /
。
- Blue backgroundColor is
ASTextNode
, Red backgroundColor isUILabel
- I found this issue show when string contains whiteSpace,
/
,;
,maybe include more symbols.
loadASTextNode
func loadTextNode(y: CGFloat, with text: String) {
let textNode = ASTextNode()
textNode.attributedText = NSAttributedString(string: text,
attributes: [NSFontAttributeName: UIFont.systemFont(ofSize: 16),
NSForegroundColorAttributeName: UIColor.red])
textNode.frame = CGRect(x: 100, y: y, width: 200, height: 20)
textNode.backgroundColor = UIColor.blue
view.addSubnode(textNode)
}
loadUILabel
func loadUILabel(y: CGFloat, with text: String) {
let label = UILabel()
label.text = text
label.textColor = UIColor.blue
label.backgroundColor = UIColor.red
label.frame = CGRect(x: 100, y: y, width: 200, height: 20)
view.addSubview(label)
}
In the TextureGroup/Texture#173, smeis said:
The difference in behavior between ASTextNode
and UILabel observed in the Demo app is caused by the fact
that the default truncation settings are different.
UILabel has NSLineBreakByTruncatingTail as default
and ASTextNode has NSLineBreakByWordWrapping as default.
If you set truncationMode to NSLineBreakByTruncatingTail
it will behave in the same manner as UILabel.
and then , I add my code:
textNode.truncationMode = .byTruncatingTail