我必须在uilabel中smily显示textview文本。
在UILabel
中-
lbl.text = @"Happy to help you \U0001F431;
它表现得很好。
在
UITextView
中-我试图将
UITextView
文本转换成字符串,然后log-%F0%9F%99%88%F0%9F%99%89%F0%9F%99%8A
如何编码,我可以显示在
UILabel
,任何人请建议我。 最佳答案
NSString *str = @"Happy to help you \U0001F431";
NSData *data = [str dataUsingEncoding:NSNonLossyASCIIStringEncoding];
NSString *valueUnicode = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSData *dataa = [valueUnicode dataUsingEncoding:NSUTF8StringEncoding];
NSString *valueEmoj = [[NSString alloc] initWithData:dataa encoding:NSNonLossyASCIIStringEncoding];
_lbl.text = valueEmoj;
SWIFT-3或更高
let str = "Happy to help you \U0001F431"
let data : NSData = str.dataUsingEncoding(NSNonLossyASCIIStringEncoding)!
let valueUnicode : String = String(data: data, encoding: NSUTF8StringEncoding)!
let dataa : NSData = valueUniCode.dataUsingEncoding(NSUTF8StringEncoding)!
let valueEmoj : String = String(data: dataa, encoding: NSNonLossyASCIIStringEncoding)!
SWIFT-4或更高
let str = "Happy to help you \U0001F431"
let data : NSData = str.dataUsingEncoding(NSNonLossyASCIIStringEncoding)!
let valueUnicode : String = String(data: data as Data, encoding: String.Encoding.utf8)!
let dataa : NSData = valueUnicode.data(using: String.Encoding.utf8)! as NSData
let valueEmoj : String = String(data: dataa as Data, encoding: String.Encoding.nonLossyASCII)!
关于objective-c - 如何在UILabel iOS中显示表情符号,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23670959/