iOS汉字转拼音(原生就支持,简单粗暴)

    NSString *txtChinese = @"我是专科生Silence";
    if ([txtChinese length]) {
        NSMutableString *txt = [[NSMutableString alloc] initWithString:txtChinese];
        if (CFStringTransform((__bridge CFMutableStringRef)txt, 0, kCFStringTransformMandarinLatin, NO)) {
            NSLog(@"带音调的拼音: %@", txt);
        }
        if (CFStringTransform((__bridge CFMutableStringRef)txt, 0, kCFStringTransformStripDiacritics, NO)) {
            NSLog(@"不带音调的拼音: %@", txt);
        }
    }

PS:此种方式仅仅适用于性能要求不高的场景!自行考量决定是否适用!

你可能感兴趣的:(iOS汉字转拼音(原生就支持,简单粗暴))