汉字拼音
A lightweight Swift library supporting convertion between Chinese (both Simplified and Tranditional) characters and Pinyin.
如何开始
Carthage
在您的 Cartfile
中指定 "HanziPinyin"。
github "teambition/HanziPinyin"
CocoaPods
在您的 Podfile
中指定 "HanziPinyin"。
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'HanziPinyin'
用法
拼音输出格式
// PinyinToneType: none, toneNumber
// PinyinVCharType: vCharacter, uUnicode, uAndColon
// PinyinCaseType: lowercased, uppercased, capitalized
let outputFormat = PinyinOutputFormat(toneType: .none, vCharType: .vCharacter, caseType: .lowercased)
转换为拼音同步
print("我爱中文".toPinyin(withFormat: outputFormat, separator: " "))
// wo ai zhong wen
print("我愛說中國話".toPinyin(withFormat: outputFormat, separator: " "))
// wo ai shuo zhong guo hua
print("我爱中文".toPinyinAcronym())
// wazw
print("I love Chinese.".toPinyin())
// I love Chinese.
转换为拼音异步
"我爱中文".toPinyin { (pinyin) in
// do something
}
"我爱中文".toPinyinAcronym { (pinyin) in
// do something
}
汉字检测
print("我爱中文".hasChineseCharacter)
// true
print("I love Chinese.".hasChineseCharacter)
// false
最小要求
iOS 8.0
版本说明
许可证
HanziPinyin遵循MIT许可证发布。详细信息请参阅LICENSE。
更多信息
有问题?请提交一个问题!