最近項(xiàng)目需要國(guó)家列表添加國(guó)旗顯示, 國(guó)旗沒(méi)有特別要求, 就想使用系統(tǒng)自帶的emoji表情顯示
含有國(guó)家簡(jiǎn)稱的json文件
swift版
func emojiFlagForISOCountryCode(countryCode:String) -> String {
let base : UInt32 = 127397
var s = ""
for v in countryCode.uppercased().unicodeScalars {
s.unicodeScalars.append(UnicodeScalar(base + v.value)!)
}
return s
}
OC版
- (NSString *)emojiFlagForISOCountryCode:(NSString *)countryCode {
int base = 127462 -65;
wchar_t bytes[2] = {
base +[code characterAtIndex:0],
base +[code characterAtIndex:1]
};
return [[NSString alloc] initWithBytes:bytes
length:code.length *sizeof(wchar_t)
encoding:NSUTF32LittleEndianStringEncoding];
}
調(diào)用
emojiFlagForISOCountryCode("CN")