NNPinyin 1.0.1

NNPinyin 1.0.1

NeroXie 保持。



NNPinyin 1.0.1

  • YiHuaXie

NNPinyin

一个轻量级的 Swift 库,支持中文(简体和繁体)与拼音之间的相互转换。

Version License Platform

如何使用

拼音输出格式

/// 音调
public enum ToneType {
    case none // 不带音调
    case toneNumber // 带音调
}

/// v的样式
public enum VCharType {
    case vCharacter // u: -> v
    case uUnicode // u: -> ü
    case uAndColon // u: -> u:
}

/// 字母样式
public enum LetterType {
    case lowercased // 小写
    case uppercased // 大写
    case capitalized // 首字母大写
}

// 定义拼音输出格式
let outputFormat = NNPinyinOutputFormat(toneType: .toneNumber, vCharType: .uAndColon, letterType: .uppercased)

转换为拼音

debugPrint("绿色".toPinyin())
// "lv se"
var outputFormat = NNPinyinOutputFormat(vCharType: .uUnicode)
debugPrint("绿色".toPinyin(withFormat: outputFormat))
// "lü se"
outputFormat = NNPinyinOutputFormat(toneType: .toneNumber, vCharType: .uAndColon, letterType: .uppercased)
debugPrint("绿色".toPinyin(withFormat: outputFormat))
// "LU:4 SE4"
debugPrint("你在幹什麼".toPinyinAcronym())
// "nzgsm"
debugPrint("Hello".toPinyin())
// "Hello"
debugPrint("测试dasdasd".hasChineseCharacter)
// true

要求

iOS 8.0

安装

pod 'NNPinyin'

作者

YiHuaXie, [email protected]

许可证

NNPinyin 提供 MIT 许可证。更多信息请查看 LICENSE 文件。