1+ (NSString *) Transform: (NSString *) Chinese2 {3Nsmutablestring *pinyin =[Chinese mutablecopy];4 Cfstringtransform ((__bridge cfmutablestringref) Pinyin, NULL, Kcfstringtransformmandarinlatin, NO);5 Cfstringtransform ((__bridge cfmutablestringref) Pinyin, NULL, Kcfstringtransformstripcombiningmarks, NO);6NSLog (@"%@", pinyin);7 return[Pinyin uppercasestring];8}
< Span class= "hljs-built_in" >< Span class= "hljs-built_in" >< Span class= "hljs-literal" >< Span class= "hljs-string" >
with Kcfstringtransformmandarinlatin
The bands method is converted to pinyin, and if you need to remove the phonetic transcription, continue using the Kcfstringtransformstripcombiningmarks
method.
However, performance may be poor in this way. Recommended use of third party-------------->> try this third-party: HTTPS://GITHUB.COM/KIMZIV/PINYIN4OBJC, support Polyphone
Below your own demo, you can Refer to the following code
nsstring *sourcetext=@ " I love Chinese " ; Hanyupinyinoutputformat *outputformat=[[hanyupinyinoutputformat alloc] init]; [OutputFormat Settonetype:tonetypewithouttone]; [OutputFormat SETVCHARTYPE:VCHARTYPEWITHV]; [OutputFormat Setcasetype:casetypelowercase]; [Pinyinhelper Tohanyupinyinstringwithnsstring:sourcetext Withhanyupinyinoutputformat:outputformat Withnsstring: @ " " Outputblock: ^ (nsstring *pinyin) {_outputtv.text =pinyin; // update UI }];
iOS kanji to Pinyin, support multi-syllable