以前一直以为,要显示各国国旗,除了让UI给图片,没有其他办法。 最近发现了手机中自带国旗,在系统表情键盘中就有各国国旗,如果对UI要求不是很高的话,可以直接使用国旗emoji 上代码 - (NSString *)emojiFlagForISOCountryCode:(NSString *)countryCode { NSString *code = countryCode; if ([countryCode isEqualToString:@"TW"]) { code = @"CN"; } NSAssert(code.length == 2, @"Expecting ISO country code"); 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]; } countryCode传国家代码,如果中国CN, [self emojiFlagForISOCountryCode:@"CN"]; 这里因为没有台湾的国旗,所以做了下判断,如果是台湾就和中国一样显示 参考链接: https://en./wiki/ISO_3166-1#Notes https:///questions/30402435/swift-turn-a-country-code-into-a-emoji-flag-via-unicode |
|