{"id":18,"date":"2023-01-02T09:38:26","date_gmt":"2023-01-02T01:38:26","guid":{"rendered":"http:\/\/www.qirimi.com\/?p=18"},"modified":"2023-01-20T11:36:23","modified_gmt":"2023-01-20T03:36:23","slug":"ios%e5%bc%80%e5%8f%91-%e4%b9%8b-%e4%b8%ad%e6%96%87%e8%bd%ac%e6%8b%bc%e9%9f%b3","status":"publish","type":"post","link":"http:\/\/www.qirimi.com\/index.php\/2023\/01\/02\/ios%e5%bc%80%e5%8f%91-%e4%b9%8b-%e4%b8%ad%e6%96%87%e8%bd%ac%e6%8b%bc%e9%9f%b3\/","title":{"rendered":"iOS\u5f00\u53d1 \u4e4b \u4e2d\u6587\u8f6c\u62fc\u97f3"},"content":{"rendered":"\n<p>\u5728\u9879\u76ee\u4e2d\u663e\u793a\u901a\u8baf\u5f55\u5f80\u5f80\u9700\u8981\u628a\u4e2d\u6587\u540d\u5b57\u8f6c\u6362\u4e3a\u62fc\u97f3\u6765\u8fdb\u884c\u6392\u5e8f\uff0c\u4e3a\u6b64\u6211\u5c01\u88c5\u4e86\u4e00\u4e2a\u7c7b\uff0c\u5c06\u4e2d\u6587\u8f6c\u4e3a\u62fc\u97f3\u5206\u4eab\u7ed9\u5927\u5bb6\u3002<\/p>\n\n\n\n<p>\u601d\u8def\u4e3b\u8981\u4e3a\uff1a<\/p>\n\n\n\n<p>1\u3001\u4f7f\u7528[CFStringTransform]\u7684[kCFStringTransformMandarinLatin]\u53ef\u4ee5\u5c06\u4e2d\u6587\u8f6c\u4e3a\u5e26\u97f3\u8c03\u7684\u62fc\u97f3<\/p>\n\n\n\n<p>2\u3001\u4f7f\u7528[CFStringTransform]\u7684[kCFStringTransformStripDiacritics]\u53ef\u4ee5\u53bb\u6389\u97f3\u8c03\u7b26\u53f7<\/p>\n\n\n\n<p>3\u3001\u904d\u5386\u5b57\u7b26\u4e32\uff0c\u5c06\u6bcf\u4e2a\u5b57\u7b26\u8f6c\u4e3a\u62fc\u97f3\u540e\u53ef\u4ee5\u53ea\u53d6\u62fc\u97f3\u9996\u5b57\u6bcd\u6765\u8fdb\u884c\u4f7f\u7528<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e00\u3001\u8be6\u7ec6\u4ee3\u7801<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\n\/\/  NSString+PinYin.m\n\/\/  ZMPinYinDemo\n\/\/\n\/\/  Created by ZengZhiming on 2017\/3\/31.\n\/\/  Copyright \u00a9 2017\u5e74 \u83dc\u9e1f\u57fa\u5730. All rights reserved.\n\/\/\n \n#import \"NSString+PinYin.h\"\n \n@implementation NSString (PinYin)\n \n \n\/**\n \u5c06\u4e2d\u6587\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u62fc\u97f3\u683c\u5f0f\uff08\u5e26\u58f0\u8c03\uff09\n @return \u8fd4\u56de\u5e26\u58f0\u8c03\u62fc\u97f3\u5b57\u7b26\u4e32\n *\/\n- (NSString *)transformToPinyinTone\n{\n    \/\/ \u7a7a\u503c\u5224\u65ad\n    if (IsNullString(self)) {\n        return @\"\";\n    }\n    \/\/ \u5c06\u5b57\u7b26\u4e32\u8f6c\u4e3aNSMutableString\u7c7b\u578b\n    NSMutableString *string = &#91;self mutableCopy];\n    \/\/ \u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u62fc\u97f3\u97f3\u8c03\u683c\u5f0f\n    CFStringTransform((__bridge CFMutableStringRef)string, NULL, kCFStringTransformMandarinLatin, NO);\n    \/\/ \u8fd4\u56de\u5e26\u58f0\u8c03\u62fc\u97f3\u5b57\u7b26\u4e32\n    return string;\n}\n \n \n\/**\n \u5c06\u4e2d\u6587\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u62fc\u97f3\u683c\u5f0f\uff08\u4e0d\u5e26\u58f0\u8c03\uff09\n @return \u8fd4\u56de\u4e0d\u5e26\u58f0\u8c03\u62fc\u97f3\u5b57\u7b26\u4e32\n *\/\n- (NSString *)transformToPinyin\n{\n    \/\/ \u7a7a\u503c\u5224\u65ad\n    if (IsNullString(self)) {\n        return @\"\";\n    }\n    \/\/ \u5c06\u5b57\u7b26\u4e32\u8f6c\u4e3aNSMutableString\u7c7b\u578b\n    NSMutableString *string = &#91;self mutableCopy];\n    \/\/ \u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u62fc\u97f3\u97f3\u8c03\u683c\u5f0f\n    CFStringTransform((__bridge CFMutableStringRef)string, NULL, kCFStringTransformMandarinLatin, NO);\n    \/\/ \u53bb\u6389\u97f3\u8c03\u7b26\u53f7\n    CFStringTransform((__bridge CFMutableStringRef)string, NULL, kCFStringTransformStripDiacritics, NO);\n    \/\/ \u8fd4\u56de\u4e0d\u5e26\u58f0\u8c03\u62fc\u97f3\u5b57\u7b26\u4e32\n    return string;\n}\n \n \n\/**\n \u5c06\u4e2d\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u62fc\u97f3\u9996\u5b57\u6bcd\n @return \u62fc\u97f3\u9996\u5b57\u6bcd\u5b57\u7b26\u4e32\n *\/\n- (NSString *)transformToFirstLetter\n{\n    \/\/ \u7a7a\u503c\u5224\u65ad\n    if (IsNullString(self)) {\n        return @\"\";\n    }\n    \/\/ \u9996\u5b57\u6bcd\u5b58\u50a8\n    NSMutableString *firstLetterStirng = &#91;NSMutableString string];\n    \/\/ \u904d\u5386\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u5b57\u7b26\n    for (NSUInteger i = 0; i &lt; self.length; i++) {\n        \/\/ \u5c06\u6bcf\u4e2a\u5b57\u7b26\u622a\u53d6\u540e\u8fdb\u884c\u62fc\u97f3\u8f6c\u6362\n        NSString *charStr = &#91;self substringWithRange:NSMakeRange(i, 1)];\n        NSString *pinyin = &#91;charStr transformToPinyin];\n        \/\/ \u5b58\u50a8\u8f6c\u6362\u540e\u7684\u62fc\u97f3\u9996\u5b57\u6bcd\n        &#91;firstLetterStirng appendString:&#91;pinyin substringToIndex:1]];\n    }\n    \/\/ \u8fd4\u56de\u4e2d\u6587\u9996\u5b57\u6bcd\u5b57\u7b26\u4e32\n    return &#91;firstLetterStirng uppercaseString];\n}\n \n@end\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e8c\u3001\u4f7f\u7528\u65b9\u5f0f<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\/** \u62fc\u97f3\u8f6c\u6362\u6309\u94ae\u70b9\u51fb *\/\n- (IBAction)onPinYinAction:(UIButton *)sender {\n    \n    \/\/ \u663e\u793a\u5e26\u58f0\u8c03\u7684\u62fc\u97f3\n    _pinyinToneLabel.text = &#91;_textField.text transformToPinyinTone];\n    \/\/ \u663e\u793a\u4e0d\u5e26\u58f0\u8c03\u7684\u62fc\u97f3\n    _pinyinLabel.text = &#91;_textField.text transformToPinyin];\n    \/\/ \u663e\u793a\u62fc\u97f3\u9996\u5b57\u6bcd\n    _firstLetterlLabel.text = &#91;_textField.text transformToFirstLetter];\n    \n}\n<\/code><\/pre>\n\n\n\n<p>Demo\u8bf7\u79fb\u6b65\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/zeng-zhiming\/ZMPinYinDemo\" target=\"_blank\">https:\/\/github.com\/zeng-zhiming\/ZMPinYinDemo<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u9879\u76ee\u4e2d\u663e\u793a\u901a\u8baf\u5f55\u5f80\u5f80\u9700\u8981\u628a\u4e2d\u6587\u540d\u5b57\u8f6c\u6362\u4e3a\u62fc\u97f3\u6765\u8fdb\u884c\u6392\u5e8f\uff0c\u4e3a\u6b64\u6211\u5c01\u88c5\u4e86\u4e00\u4e2a\u7c7b\uff0c\u5c06\u4e2d\u6587\u8f6c\u4e3a\u62fc\u97f3\u5206\u4eab\u7ed9\u5927\u5bb6\u3002 \u601d\u8def [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[2,5],"class_list":["post-18","post","type-post","status-publish","format-standard","hentry","category-3","tag-ios","tag-5"],"_links":{"self":[{"href":"http:\/\/www.qirimi.com\/index.php\/wp-json\/wp\/v2\/posts\/18","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.qirimi.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.qirimi.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.qirimi.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.qirimi.com\/index.php\/wp-json\/wp\/v2\/comments?post=18"}],"version-history":[{"count":7,"href":"http:\/\/www.qirimi.com\/index.php\/wp-json\/wp\/v2\/posts\/18\/revisions"}],"predecessor-version":[{"id":28,"href":"http:\/\/www.qirimi.com\/index.php\/wp-json\/wp\/v2\/posts\/18\/revisions\/28"}],"wp:attachment":[{"href":"http:\/\/www.qirimi.com\/index.php\/wp-json\/wp\/v2\/media?parent=18"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.qirimi.com\/index.php\/wp-json\/wp\/v2\/categories?post=18"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.qirimi.com\/index.php\/wp-json\/wp\/v2\/tags?post=18"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}