iOS中文转拼音

可以带音标也可以不带,转出来带拼音带空格,可以自行去掉

NSMutableString *testString = [[NSMutableString alloc] initWithString:@"你好,旅行者!"];
if (CFStringTransform((__bridge CFMutableStringRef)testString, 0, kCFStringTransformMandarinLatin, NO)) {
    NSLog(@"带音标: %@", testString);
}
if (CFStringTransform((__bridge CFMutableStringRef)testString, 0, kCFStringTransformStripDiacritics, NO)) {
    NSLog(@"不带音标: %@", testString);
}

你可能感兴趣的:(iOS中文转拼音)