[英]How to set the title of a UIButton in a UICollectionViewCell with Swift
[英]How to set unicode emoji to the the title of a UIButton in Swift 3?
编辑:找到了一种将其转换为大量转换的方法,但显得草率:
let myStr = "1f601"
let str = String(Character(UnicodeScalar(Int(myStr, radix: 16)!)!))
我正在尝试执行以下操作:
for _ in 1...2 {
let emojiButton = UIButton()
emojiButton.backgroundColor = UIColor.green
emojiButton.heightAnchor.constraint(equalToConstant: 20.0).isActive = true
emojiButton.titleLabel!.font = UIFont(name: "AppleColorEmoji", size: CGFloat(16.0))
emojiButton.setTitle(str, for: .normal)
stackView.addArrangedSubview(emojiButton)
}
由于某种原因,这给出了两个不同的符号,而不是预期的表情符号,结果如下:
所以现在我对%C格式为什么不显示unicode以及为什么它显示两个不同字符感到困惑。
let myStr = "\u{1f601}"
这可能是在Swift中指定Unicode点的最简单方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.