├── .gitignore ├── 2017-06-27 10_57_40.gif ├── LICENSE ├── README.md ├── ZYPinYinSearch.podspec ├── ZYPinYinSearch.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── ZYPinYinSearch.xccheckout │ └── xcuserdata │ │ └── soufun.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── soufun.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── ZYPinYinSearch.xcscheme │ └── xcschememanagement.plist └── ZYPinYinSearch ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj ├── LaunchScreen.xib └── Main.storyboard ├── Images.xcassets ├── AppIcon.appiconset │ └── Contents.json ├── backArrow.imageset │ ├── Contents.json │ └── backArrow.png └── searchButton.imageset │ ├── Contents.json │ └── searchButton.png ├── Info.plist ├── Person.h ├── Person.m ├── PrefixHeader.pch ├── ViewController.h ├── ViewController.m ├── ZYPinYinSearchLib ├── ChineseInclude.h ├── ChineseInclude.m ├── ChineseToPinyinResource.h ├── ChineseToPinyinResource.m ├── HanyuPinyinOutputFormat.h ├── HanyuPinyinOutputFormat.m ├── NSString+PinYin4Cocoa.h ├── NSString+PinYin4Cocoa.m ├── PinYinForObjc.h ├── PinYinForObjc.m ├── PinyinFormatter.h ├── PinyinFormatter.m ├── PinyinHelper.h ├── PinyinHelper.m ├── ZYPinYinSearch.h ├── ZYPinYinSearch.m ├── ZYSearchModel.h ├── ZYSearchModel.m └── unicode_to_hanyu_pinyin.txt ├── ZYSearchViewController.h ├── ZYSearchViewController.m └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | ZYPinYinSearch.xcodeproj/project.xcworkspace/xcshareddata/ZYPinYinSearch.xcscmblueprint 3 | ZYPinYinSearch.xcodeproj/project.xcworkspace/xcuserdata/tarena.xcuserdatad/UserInterfaceState.xcuserstate 4 | ZYPinYinSearch.xcodeproj/xcuserdata/tarena.xcuserdatad/xcschemes/xcschememanagement.plist 5 | ZYPinYinSearch.xcodeproj/xcuserdata/tarena.xcuserdatad/xcschemes/ZYPinYinSearch.xcscheme 6 | -------------------------------------------------------------------------------- /2017-06-27 10_57_40.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bjzhangyang/ZYPinYinSearch/d915edc23dd4c7201b18a256bd38969907b6733a/2017-06-27 10_57_40.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2020 ZYPinYinSearch (https://github.com/bjzhangyang/ZYPinYinSearch) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ## ZYPinYinSearch是什么? 3 | 一个筛选库,可以把数组里的内容按照拼音筛选出来。 4 | 5 | ## ZYPinYinSearch有哪些功能? 6 | 7 | * 搜索功能 8 | * 数据源可以是字符串的数组 9 | * 数据源可以是字典的数组,按照某个字段搜索 10 | * 数据源可以是自定义Model的数组,按照某个字段搜索 11 | * 自定义多音字功能。可以指定某个词语或者汉字为某个拼音,仅需设置一次,在APP运行过程中都有效 12 | 13 | ## ZYPinYinSearch怎么用 14 | ```javascript 15 | /** 16 | * 搜索数组,返回新的数组。目前支持NSString,NSDictionnary,自定义Model,后面两个可以指定按照哪个字段搜索 17 | * 18 | * @param originalArray 要搜索的数据源 19 | * @param searchText 搜索的文本 20 | * @param propertyName 按照字典中或者model中哪个字段搜索,如果数组中存的是NSString,则传@""即可 21 | */ 22 | [ZYPinYinSearch searchByPropertyName:@"name" withOriginalArray:_originalArray searchText:searchBar.text success:^(NSArray *results) { 23 | _dataSourceArray = results; 24 | [_tableView reloadData]; 25 | } failure:^(NSString *errorMessage) { 26 | 27 | }]; 28 | 29 | //处理多音字,指定词组的拼音,指定一次,整个APP运行过程中都有效,可以手动清除 30 | [ZYPinYinSearch setupReplacement:^NSDictionary *{ 31 | return @{@"长春":@"changchun",@"重庆":@"chongqing"};//长春默认是"zhangchun",所以咱们这里可以特殊设置成"changchun" 32 | }]; 33 | ``` 34 | ## 安装 35 | 1、pod 'ZYPinYinSearch' 36 | 2、或者直接把ZYPinYinSearchLib拖入项目即可 37 | ![img](https://github.com/bjzhangyang/ZYPinYinSearch/blob/master/2017-06-27%2010_57_40.gif) 38 | -------------------------------------------------------------------------------- /ZYPinYinSearch.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "ZYPinYinSearch" 3 | s.version = "2.0.1" 4 | s.ios.deployment_target = '6.0' 5 | s.summary = "iOS汉语拼音搜索" 6 | s.homepage = "https://github.com/bjzhangyang/ZYPinYinSearch" 7 | s.license = "MIT" 8 | s.author = { "bjzhangyang" => "348487330@qq.com" } 9 | s.source = { :git => "https://github.com/bjzhangyang/ZYPinYinSearch", :tag => s.version } 10 | s.source_files = "ZYPinYinSearch/ZYPinYinSearchLib/*" 11 | s.requires_arc = true 12 | end 13 | -------------------------------------------------------------------------------- /ZYPinYinSearch.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 5AE26F911B65C6AE008C06ED /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AE26F901B65C6AE008C06ED /* main.m */; }; 11 | 5AE26F941B65C6AE008C06ED /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AE26F931B65C6AE008C06ED /* AppDelegate.m */; }; 12 | 5AE26F971B65C6AE008C06ED /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AE26F961B65C6AE008C06ED /* ViewController.m */; }; 13 | 5AE26F9A1B65C6AE008C06ED /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5AE26F981B65C6AE008C06ED /* Main.storyboard */; }; 14 | 5AE26F9C1B65C6AE008C06ED /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5AE26F9B1B65C6AE008C06ED /* Images.xcassets */; }; 15 | 5AE26F9F1B65C6AE008C06ED /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5AE26F9D1B65C6AE008C06ED /* LaunchScreen.xib */; }; 16 | 5AE26FD31B65F877008C06ED /* ZYSearchViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AE26FD21B65F877008C06ED /* ZYSearchViewController.m */; }; 17 | 5AE26FD91B6605CA008C06ED /* Person.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AE26FD81B6605CA008C06ED /* Person.m */; }; 18 | 5AE26FEE1B662C83008C06ED /* ChineseInclude.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AE26FDE1B662C83008C06ED /* ChineseInclude.m */; }; 19 | 5AE26FEF1B662C83008C06ED /* ChineseToPinyinResource.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AE26FE01B662C83008C06ED /* ChineseToPinyinResource.m */; }; 20 | 5AE26FF01B662C83008C06ED /* HanyuPinyinOutputFormat.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AE26FE21B662C83008C06ED /* HanyuPinyinOutputFormat.m */; }; 21 | 5AE26FF11B662C83008C06ED /* NSString+PinYin4Cocoa.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AE26FE41B662C83008C06ED /* NSString+PinYin4Cocoa.m */; }; 22 | 5AE26FF21B662C83008C06ED /* PinyinFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AE26FE61B662C83008C06ED /* PinyinFormatter.m */; }; 23 | 5AE26FF31B662C83008C06ED /* PinYinForObjc.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AE26FE81B662C83008C06ED /* PinYinForObjc.m */; }; 24 | 5AE26FF41B662C83008C06ED /* PinyinHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AE26FEA1B662C83008C06ED /* PinyinHelper.m */; }; 25 | 5AE26FF51B662C83008C06ED /* unicode_to_hanyu_pinyin.txt in Resources */ = {isa = PBXBuildFile; fileRef = 5AE26FEB1B662C83008C06ED /* unicode_to_hanyu_pinyin.txt */; }; 26 | 5AE26FF61B662C83008C06ED /* ZYPinYinSearch.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AE26FED1B662C83008C06ED /* ZYPinYinSearch.m */; }; 27 | 85F6BAAB1EEFAB2700C53B9F /* ZYSearchModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 85F6BAAA1EEFAB2700C53B9F /* ZYSearchModel.m */; }; 28 | /* End PBXBuildFile section */ 29 | 30 | /* Begin PBXContainerItemProxy section */ 31 | 5AE26FA51B65C6AE008C06ED /* PBXContainerItemProxy */ = { 32 | isa = PBXContainerItemProxy; 33 | containerPortal = 5AE26F831B65C6AE008C06ED /* Project object */; 34 | proxyType = 1; 35 | remoteGlobalIDString = 5AE26F8A1B65C6AE008C06ED; 36 | remoteInfo = ZYPinYinSearch; 37 | }; 38 | /* End PBXContainerItemProxy section */ 39 | 40 | /* Begin PBXFileReference section */ 41 | 5AE26F8B1B65C6AE008C06ED /* ZYPinYinSearch.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ZYPinYinSearch.app; sourceTree = BUILT_PRODUCTS_DIR; }; 42 | 5AE26F8F1B65C6AE008C06ED /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 43 | 5AE26F901B65C6AE008C06ED /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 44 | 5AE26F921B65C6AE008C06ED /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 45 | 5AE26F931B65C6AE008C06ED /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 46 | 5AE26F951B65C6AE008C06ED /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 47 | 5AE26F961B65C6AE008C06ED /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 48 | 5AE26F991B65C6AE008C06ED /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 49 | 5AE26F9B1B65C6AE008C06ED /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 50 | 5AE26F9E1B65C6AE008C06ED /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 51 | 5AE26FA41B65C6AE008C06ED /* ZYPinYinSearchTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ZYPinYinSearchTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 52 | 5AE26FCD1B65F41A008C06ED /* PrefixHeader.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PrefixHeader.pch; sourceTree = ""; }; 53 | 5AE26FD11B65F877008C06ED /* ZYSearchViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZYSearchViewController.h; sourceTree = ""; }; 54 | 5AE26FD21B65F877008C06ED /* ZYSearchViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZYSearchViewController.m; sourceTree = ""; }; 55 | 5AE26FD71B6605CA008C06ED /* Person.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Person.h; sourceTree = ""; }; 56 | 5AE26FD81B6605CA008C06ED /* Person.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Person.m; sourceTree = ""; }; 57 | 5AE26FDD1B662C83008C06ED /* ChineseInclude.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ChineseInclude.h; sourceTree = ""; }; 58 | 5AE26FDE1B662C83008C06ED /* ChineseInclude.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ChineseInclude.m; sourceTree = ""; }; 59 | 5AE26FDF1B662C83008C06ED /* ChineseToPinyinResource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ChineseToPinyinResource.h; sourceTree = ""; }; 60 | 5AE26FE01B662C83008C06ED /* ChineseToPinyinResource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ChineseToPinyinResource.m; sourceTree = ""; }; 61 | 5AE26FE11B662C83008C06ED /* HanyuPinyinOutputFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HanyuPinyinOutputFormat.h; sourceTree = ""; }; 62 | 5AE26FE21B662C83008C06ED /* HanyuPinyinOutputFormat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HanyuPinyinOutputFormat.m; sourceTree = ""; }; 63 | 5AE26FE31B662C83008C06ED /* NSString+PinYin4Cocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+PinYin4Cocoa.h"; sourceTree = ""; }; 64 | 5AE26FE41B662C83008C06ED /* NSString+PinYin4Cocoa.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+PinYin4Cocoa.m"; sourceTree = ""; }; 65 | 5AE26FE51B662C83008C06ED /* PinyinFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PinyinFormatter.h; sourceTree = ""; }; 66 | 5AE26FE61B662C83008C06ED /* PinyinFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PinyinFormatter.m; sourceTree = ""; }; 67 | 5AE26FE71B662C83008C06ED /* PinYinForObjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PinYinForObjc.h; sourceTree = ""; }; 68 | 5AE26FE81B662C83008C06ED /* PinYinForObjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PinYinForObjc.m; sourceTree = ""; }; 69 | 5AE26FE91B662C83008C06ED /* PinyinHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PinyinHelper.h; sourceTree = ""; }; 70 | 5AE26FEA1B662C83008C06ED /* PinyinHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PinyinHelper.m; sourceTree = ""; }; 71 | 5AE26FEB1B662C83008C06ED /* unicode_to_hanyu_pinyin.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = unicode_to_hanyu_pinyin.txt; sourceTree = ""; }; 72 | 5AE26FEC1B662C83008C06ED /* ZYPinYinSearch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZYPinYinSearch.h; sourceTree = ""; }; 73 | 5AE26FED1B662C83008C06ED /* ZYPinYinSearch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZYPinYinSearch.m; sourceTree = ""; }; 74 | 85F6BAA71EEF91FC00C53B9F /* ZYSearchModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZYSearchModel.h; sourceTree = ""; }; 75 | 85F6BAAA1EEFAB2700C53B9F /* ZYSearchModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZYSearchModel.m; sourceTree = ""; }; 76 | /* End PBXFileReference section */ 77 | 78 | /* Begin PBXFrameworksBuildPhase section */ 79 | 5AE26F881B65C6AE008C06ED /* Frameworks */ = { 80 | isa = PBXFrameworksBuildPhase; 81 | buildActionMask = 2147483647; 82 | files = ( 83 | ); 84 | runOnlyForDeploymentPostprocessing = 0; 85 | }; 86 | 5AE26FA11B65C6AE008C06ED /* Frameworks */ = { 87 | isa = PBXFrameworksBuildPhase; 88 | buildActionMask = 2147483647; 89 | files = ( 90 | ); 91 | runOnlyForDeploymentPostprocessing = 0; 92 | }; 93 | /* End PBXFrameworksBuildPhase section */ 94 | 95 | /* Begin PBXGroup section */ 96 | 5AE26F821B65C6AE008C06ED = { 97 | isa = PBXGroup; 98 | children = ( 99 | 5AE26F8D1B65C6AE008C06ED /* ZYPinYinSearch */, 100 | 5AE26F8C1B65C6AE008C06ED /* Products */, 101 | ); 102 | sourceTree = ""; 103 | }; 104 | 5AE26F8C1B65C6AE008C06ED /* Products */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | 5AE26F8B1B65C6AE008C06ED /* ZYPinYinSearch.app */, 108 | 5AE26FA41B65C6AE008C06ED /* ZYPinYinSearchTests.xctest */, 109 | ); 110 | name = Products; 111 | sourceTree = ""; 112 | }; 113 | 5AE26F8D1B65C6AE008C06ED /* ZYPinYinSearch */ = { 114 | isa = PBXGroup; 115 | children = ( 116 | 5AE26FDC1B662C83008C06ED /* ZYPinYinSearchLib */, 117 | 5AE26F921B65C6AE008C06ED /* AppDelegate.h */, 118 | 5AE26F931B65C6AE008C06ED /* AppDelegate.m */, 119 | 5AE26F951B65C6AE008C06ED /* ViewController.h */, 120 | 5AE26F961B65C6AE008C06ED /* ViewController.m */, 121 | 5AE26FD11B65F877008C06ED /* ZYSearchViewController.h */, 122 | 5AE26FD21B65F877008C06ED /* ZYSearchViewController.m */, 123 | 5AE26FD71B6605CA008C06ED /* Person.h */, 124 | 5AE26FD81B6605CA008C06ED /* Person.m */, 125 | 5AE26F981B65C6AE008C06ED /* Main.storyboard */, 126 | 5AE26F9B1B65C6AE008C06ED /* Images.xcassets */, 127 | 5AE26F9D1B65C6AE008C06ED /* LaunchScreen.xib */, 128 | 5AE26F8E1B65C6AE008C06ED /* Supporting Files */, 129 | ); 130 | path = ZYPinYinSearch; 131 | sourceTree = ""; 132 | }; 133 | 5AE26F8E1B65C6AE008C06ED /* Supporting Files */ = { 134 | isa = PBXGroup; 135 | children = ( 136 | 5AE26F8F1B65C6AE008C06ED /* Info.plist */, 137 | 5AE26F901B65C6AE008C06ED /* main.m */, 138 | 5AE26FCD1B65F41A008C06ED /* PrefixHeader.pch */, 139 | ); 140 | name = "Supporting Files"; 141 | sourceTree = ""; 142 | }; 143 | 5AE26FDC1B662C83008C06ED /* ZYPinYinSearchLib */ = { 144 | isa = PBXGroup; 145 | children = ( 146 | 5AE26FDD1B662C83008C06ED /* ChineseInclude.h */, 147 | 5AE26FDE1B662C83008C06ED /* ChineseInclude.m */, 148 | 5AE26FDF1B662C83008C06ED /* ChineseToPinyinResource.h */, 149 | 5AE26FE01B662C83008C06ED /* ChineseToPinyinResource.m */, 150 | 5AE26FE11B662C83008C06ED /* HanyuPinyinOutputFormat.h */, 151 | 5AE26FE21B662C83008C06ED /* HanyuPinyinOutputFormat.m */, 152 | 5AE26FE31B662C83008C06ED /* NSString+PinYin4Cocoa.h */, 153 | 5AE26FE41B662C83008C06ED /* NSString+PinYin4Cocoa.m */, 154 | 5AE26FE51B662C83008C06ED /* PinyinFormatter.h */, 155 | 5AE26FE61B662C83008C06ED /* PinyinFormatter.m */, 156 | 5AE26FE71B662C83008C06ED /* PinYinForObjc.h */, 157 | 5AE26FE81B662C83008C06ED /* PinYinForObjc.m */, 158 | 5AE26FE91B662C83008C06ED /* PinyinHelper.h */, 159 | 5AE26FEA1B662C83008C06ED /* PinyinHelper.m */, 160 | 5AE26FEB1B662C83008C06ED /* unicode_to_hanyu_pinyin.txt */, 161 | 85F6BAA71EEF91FC00C53B9F /* ZYSearchModel.h */, 162 | 85F6BAAA1EEFAB2700C53B9F /* ZYSearchModel.m */, 163 | 5AE26FEC1B662C83008C06ED /* ZYPinYinSearch.h */, 164 | 5AE26FED1B662C83008C06ED /* ZYPinYinSearch.m */, 165 | ); 166 | path = ZYPinYinSearchLib; 167 | sourceTree = ""; 168 | }; 169 | /* End PBXGroup section */ 170 | 171 | /* Begin PBXNativeTarget section */ 172 | 5AE26F8A1B65C6AE008C06ED /* ZYPinYinSearch */ = { 173 | isa = PBXNativeTarget; 174 | buildConfigurationList = 5AE26FAE1B65C6AF008C06ED /* Build configuration list for PBXNativeTarget "ZYPinYinSearch" */; 175 | buildPhases = ( 176 | 5AE26F871B65C6AE008C06ED /* Sources */, 177 | 5AE26F881B65C6AE008C06ED /* Frameworks */, 178 | 5AE26F891B65C6AE008C06ED /* Resources */, 179 | ); 180 | buildRules = ( 181 | ); 182 | dependencies = ( 183 | ); 184 | name = ZYPinYinSearch; 185 | productName = ZYPinYinSearch; 186 | productReference = 5AE26F8B1B65C6AE008C06ED /* ZYPinYinSearch.app */; 187 | productType = "com.apple.product-type.application"; 188 | }; 189 | 5AE26FA31B65C6AE008C06ED /* ZYPinYinSearchTests */ = { 190 | isa = PBXNativeTarget; 191 | buildConfigurationList = 5AE26FB11B65C6AF008C06ED /* Build configuration list for PBXNativeTarget "ZYPinYinSearchTests" */; 192 | buildPhases = ( 193 | 5AE26FA01B65C6AE008C06ED /* Sources */, 194 | 5AE26FA11B65C6AE008C06ED /* Frameworks */, 195 | 5AE26FA21B65C6AE008C06ED /* Resources */, 196 | ); 197 | buildRules = ( 198 | ); 199 | dependencies = ( 200 | 5AE26FA61B65C6AE008C06ED /* PBXTargetDependency */, 201 | ); 202 | name = ZYPinYinSearchTests; 203 | productName = ZYPinYinSearchTests; 204 | productReference = 5AE26FA41B65C6AE008C06ED /* ZYPinYinSearchTests.xctest */; 205 | productType = "com.apple.product-type.bundle.unit-test"; 206 | }; 207 | /* End PBXNativeTarget section */ 208 | 209 | /* Begin PBXProject section */ 210 | 5AE26F831B65C6AE008C06ED /* Project object */ = { 211 | isa = PBXProject; 212 | attributes = { 213 | LastUpgradeCheck = 0640; 214 | ORGANIZATIONNAME = ZY; 215 | TargetAttributes = { 216 | 5AE26F8A1B65C6AE008C06ED = { 217 | CreatedOnToolsVersion = 6.4; 218 | ProvisioningStyle = Manual; 219 | }; 220 | 5AE26FA31B65C6AE008C06ED = { 221 | CreatedOnToolsVersion = 6.4; 222 | TestTargetID = 5AE26F8A1B65C6AE008C06ED; 223 | }; 224 | }; 225 | }; 226 | buildConfigurationList = 5AE26F861B65C6AE008C06ED /* Build configuration list for PBXProject "ZYPinYinSearch" */; 227 | compatibilityVersion = "Xcode 3.2"; 228 | developmentRegion = English; 229 | hasScannedForEncodings = 0; 230 | knownRegions = ( 231 | en, 232 | Base, 233 | ); 234 | mainGroup = 5AE26F821B65C6AE008C06ED; 235 | productRefGroup = 5AE26F8C1B65C6AE008C06ED /* Products */; 236 | projectDirPath = ""; 237 | projectRoot = ""; 238 | targets = ( 239 | 5AE26F8A1B65C6AE008C06ED /* ZYPinYinSearch */, 240 | 5AE26FA31B65C6AE008C06ED /* ZYPinYinSearchTests */, 241 | ); 242 | }; 243 | /* End PBXProject section */ 244 | 245 | /* Begin PBXResourcesBuildPhase section */ 246 | 5AE26F891B65C6AE008C06ED /* Resources */ = { 247 | isa = PBXResourcesBuildPhase; 248 | buildActionMask = 2147483647; 249 | files = ( 250 | 5AE26FF51B662C83008C06ED /* unicode_to_hanyu_pinyin.txt in Resources */, 251 | 5AE26F9A1B65C6AE008C06ED /* Main.storyboard in Resources */, 252 | 5AE26F9F1B65C6AE008C06ED /* LaunchScreen.xib in Resources */, 253 | 5AE26F9C1B65C6AE008C06ED /* Images.xcassets in Resources */, 254 | ); 255 | runOnlyForDeploymentPostprocessing = 0; 256 | }; 257 | 5AE26FA21B65C6AE008C06ED /* Resources */ = { 258 | isa = PBXResourcesBuildPhase; 259 | buildActionMask = 2147483647; 260 | files = ( 261 | ); 262 | runOnlyForDeploymentPostprocessing = 0; 263 | }; 264 | /* End PBXResourcesBuildPhase section */ 265 | 266 | /* Begin PBXSourcesBuildPhase section */ 267 | 5AE26F871B65C6AE008C06ED /* Sources */ = { 268 | isa = PBXSourcesBuildPhase; 269 | buildActionMask = 2147483647; 270 | files = ( 271 | 5AE26FF41B662C83008C06ED /* PinyinHelper.m in Sources */, 272 | 5AE26FEE1B662C83008C06ED /* ChineseInclude.m in Sources */, 273 | 5AE26F971B65C6AE008C06ED /* ViewController.m in Sources */, 274 | 5AE26FF61B662C83008C06ED /* ZYPinYinSearch.m in Sources */, 275 | 5AE26FF01B662C83008C06ED /* HanyuPinyinOutputFormat.m in Sources */, 276 | 85F6BAAB1EEFAB2700C53B9F /* ZYSearchModel.m in Sources */, 277 | 5AE26FF11B662C83008C06ED /* NSString+PinYin4Cocoa.m in Sources */, 278 | 5AE26F941B65C6AE008C06ED /* AppDelegate.m in Sources */, 279 | 5AE26FF21B662C83008C06ED /* PinyinFormatter.m in Sources */, 280 | 5AE26F911B65C6AE008C06ED /* main.m in Sources */, 281 | 5AE26FD91B6605CA008C06ED /* Person.m in Sources */, 282 | 5AE26FD31B65F877008C06ED /* ZYSearchViewController.m in Sources */, 283 | 5AE26FEF1B662C83008C06ED /* ChineseToPinyinResource.m in Sources */, 284 | 5AE26FF31B662C83008C06ED /* PinYinForObjc.m in Sources */, 285 | ); 286 | runOnlyForDeploymentPostprocessing = 0; 287 | }; 288 | 5AE26FA01B65C6AE008C06ED /* Sources */ = { 289 | isa = PBXSourcesBuildPhase; 290 | buildActionMask = 2147483647; 291 | files = ( 292 | ); 293 | runOnlyForDeploymentPostprocessing = 0; 294 | }; 295 | /* End PBXSourcesBuildPhase section */ 296 | 297 | /* Begin PBXTargetDependency section */ 298 | 5AE26FA61B65C6AE008C06ED /* PBXTargetDependency */ = { 299 | isa = PBXTargetDependency; 300 | target = 5AE26F8A1B65C6AE008C06ED /* ZYPinYinSearch */; 301 | targetProxy = 5AE26FA51B65C6AE008C06ED /* PBXContainerItemProxy */; 302 | }; 303 | /* End PBXTargetDependency section */ 304 | 305 | /* Begin PBXVariantGroup section */ 306 | 5AE26F981B65C6AE008C06ED /* Main.storyboard */ = { 307 | isa = PBXVariantGroup; 308 | children = ( 309 | 5AE26F991B65C6AE008C06ED /* Base */, 310 | ); 311 | name = Main.storyboard; 312 | sourceTree = ""; 313 | }; 314 | 5AE26F9D1B65C6AE008C06ED /* LaunchScreen.xib */ = { 315 | isa = PBXVariantGroup; 316 | children = ( 317 | 5AE26F9E1B65C6AE008C06ED /* Base */, 318 | ); 319 | name = LaunchScreen.xib; 320 | sourceTree = ""; 321 | }; 322 | /* End PBXVariantGroup section */ 323 | 324 | /* Begin XCBuildConfiguration section */ 325 | 5AE26FAC1B65C6AF008C06ED /* Debug */ = { 326 | isa = XCBuildConfiguration; 327 | buildSettings = { 328 | ALWAYS_SEARCH_USER_PATHS = NO; 329 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 330 | CLANG_CXX_LIBRARY = "libc++"; 331 | CLANG_ENABLE_MODULES = YES; 332 | CLANG_ENABLE_OBJC_ARC = YES; 333 | CLANG_WARN_BOOL_CONVERSION = YES; 334 | CLANG_WARN_CONSTANT_CONVERSION = YES; 335 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 336 | CLANG_WARN_EMPTY_BODY = YES; 337 | CLANG_WARN_ENUM_CONVERSION = YES; 338 | CLANG_WARN_INT_CONVERSION = YES; 339 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 340 | CLANG_WARN_UNREACHABLE_CODE = YES; 341 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 342 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 343 | COPY_PHASE_STRIP = NO; 344 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 345 | ENABLE_STRICT_OBJC_MSGSEND = YES; 346 | GCC_C_LANGUAGE_STANDARD = gnu99; 347 | GCC_DYNAMIC_NO_PIC = NO; 348 | GCC_NO_COMMON_BLOCKS = YES; 349 | GCC_OPTIMIZATION_LEVEL = 0; 350 | GCC_PREPROCESSOR_DEFINITIONS = ( 351 | "DEBUG=1", 352 | "$(inherited)", 353 | ); 354 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 355 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 356 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 357 | GCC_WARN_UNDECLARED_SELECTOR = YES; 358 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 359 | GCC_WARN_UNUSED_FUNCTION = YES; 360 | GCC_WARN_UNUSED_VARIABLE = YES; 361 | IPHONEOS_DEPLOYMENT_TARGET = 8.4; 362 | MTL_ENABLE_DEBUG_INFO = YES; 363 | ONLY_ACTIVE_ARCH = YES; 364 | SDKROOT = iphoneos; 365 | TARGETED_DEVICE_FAMILY = "1,2"; 366 | }; 367 | name = Debug; 368 | }; 369 | 5AE26FAD1B65C6AF008C06ED /* Release */ = { 370 | isa = XCBuildConfiguration; 371 | buildSettings = { 372 | ALWAYS_SEARCH_USER_PATHS = NO; 373 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 374 | CLANG_CXX_LIBRARY = "libc++"; 375 | CLANG_ENABLE_MODULES = YES; 376 | CLANG_ENABLE_OBJC_ARC = YES; 377 | CLANG_WARN_BOOL_CONVERSION = YES; 378 | CLANG_WARN_CONSTANT_CONVERSION = YES; 379 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 380 | CLANG_WARN_EMPTY_BODY = YES; 381 | CLANG_WARN_ENUM_CONVERSION = YES; 382 | CLANG_WARN_INT_CONVERSION = YES; 383 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 384 | CLANG_WARN_UNREACHABLE_CODE = YES; 385 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 386 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 387 | COPY_PHASE_STRIP = NO; 388 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 389 | ENABLE_NS_ASSERTIONS = NO; 390 | ENABLE_STRICT_OBJC_MSGSEND = YES; 391 | GCC_C_LANGUAGE_STANDARD = gnu99; 392 | GCC_NO_COMMON_BLOCKS = YES; 393 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 394 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 395 | GCC_WARN_UNDECLARED_SELECTOR = YES; 396 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 397 | GCC_WARN_UNUSED_FUNCTION = YES; 398 | GCC_WARN_UNUSED_VARIABLE = YES; 399 | IPHONEOS_DEPLOYMENT_TARGET = 8.4; 400 | MTL_ENABLE_DEBUG_INFO = NO; 401 | SDKROOT = iphoneos; 402 | TARGETED_DEVICE_FAMILY = "1,2"; 403 | VALIDATE_PRODUCT = YES; 404 | }; 405 | name = Release; 406 | }; 407 | 5AE26FAF1B65C6AF008C06ED /* Debug */ = { 408 | isa = XCBuildConfiguration; 409 | buildSettings = { 410 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 411 | DEVELOPMENT_TEAM = ""; 412 | GCC_PREFIX_HEADER = ZYPinYinSearch/PrefixHeader.pch; 413 | INFOPLIST_FILE = ZYPinYinSearch/Info.plist; 414 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 415 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 416 | PRODUCT_NAME = "$(TARGET_NAME)"; 417 | WARNING_CFLAGS = "-Wno-shorten-64-to-32"; 418 | }; 419 | name = Debug; 420 | }; 421 | 5AE26FB01B65C6AF008C06ED /* Release */ = { 422 | isa = XCBuildConfiguration; 423 | buildSettings = { 424 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 425 | DEVELOPMENT_TEAM = ""; 426 | GCC_PREFIX_HEADER = ZYPinYinSearch/PrefixHeader.pch; 427 | INFOPLIST_FILE = ZYPinYinSearch/Info.plist; 428 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 429 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 430 | PRODUCT_NAME = "$(TARGET_NAME)"; 431 | WARNING_CFLAGS = "-Wno-shorten-64-to-32"; 432 | }; 433 | name = Release; 434 | }; 435 | 5AE26FB21B65C6AF008C06ED /* Debug */ = { 436 | isa = XCBuildConfiguration; 437 | buildSettings = { 438 | BUNDLE_LOADER = "$(TEST_HOST)"; 439 | FRAMEWORK_SEARCH_PATHS = ( 440 | "$(SDKROOT)/Developer/Library/Frameworks", 441 | "$(inherited)", 442 | ); 443 | GCC_PREPROCESSOR_DEFINITIONS = ( 444 | "DEBUG=1", 445 | "$(inherited)", 446 | ); 447 | INFOPLIST_FILE = ZYPinYinSearchTests/Info.plist; 448 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 449 | PRODUCT_NAME = "$(TARGET_NAME)"; 450 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ZYPinYinSearch.app/ZYPinYinSearch"; 451 | }; 452 | name = Debug; 453 | }; 454 | 5AE26FB31B65C6AF008C06ED /* Release */ = { 455 | isa = XCBuildConfiguration; 456 | buildSettings = { 457 | BUNDLE_LOADER = "$(TEST_HOST)"; 458 | FRAMEWORK_SEARCH_PATHS = ( 459 | "$(SDKROOT)/Developer/Library/Frameworks", 460 | "$(inherited)", 461 | ); 462 | INFOPLIST_FILE = ZYPinYinSearchTests/Info.plist; 463 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 464 | PRODUCT_NAME = "$(TARGET_NAME)"; 465 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ZYPinYinSearch.app/ZYPinYinSearch"; 466 | }; 467 | name = Release; 468 | }; 469 | /* End XCBuildConfiguration section */ 470 | 471 | /* Begin XCConfigurationList section */ 472 | 5AE26F861B65C6AE008C06ED /* Build configuration list for PBXProject "ZYPinYinSearch" */ = { 473 | isa = XCConfigurationList; 474 | buildConfigurations = ( 475 | 5AE26FAC1B65C6AF008C06ED /* Debug */, 476 | 5AE26FAD1B65C6AF008C06ED /* Release */, 477 | ); 478 | defaultConfigurationIsVisible = 0; 479 | defaultConfigurationName = Release; 480 | }; 481 | 5AE26FAE1B65C6AF008C06ED /* Build configuration list for PBXNativeTarget "ZYPinYinSearch" */ = { 482 | isa = XCConfigurationList; 483 | buildConfigurations = ( 484 | 5AE26FAF1B65C6AF008C06ED /* Debug */, 485 | 5AE26FB01B65C6AF008C06ED /* Release */, 486 | ); 487 | defaultConfigurationIsVisible = 0; 488 | defaultConfigurationName = Release; 489 | }; 490 | 5AE26FB11B65C6AF008C06ED /* Build configuration list for PBXNativeTarget "ZYPinYinSearchTests" */ = { 491 | isa = XCConfigurationList; 492 | buildConfigurations = ( 493 | 5AE26FB21B65C6AF008C06ED /* Debug */, 494 | 5AE26FB31B65C6AF008C06ED /* Release */, 495 | ); 496 | defaultConfigurationIsVisible = 0; 497 | defaultConfigurationName = Release; 498 | }; 499 | /* End XCConfigurationList section */ 500 | }; 501 | rootObject = 5AE26F831B65C6AE008C06ED /* Project object */; 502 | } 503 | -------------------------------------------------------------------------------- /ZYPinYinSearch.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ZYPinYinSearch.xcodeproj/project.xcworkspace/xcshareddata/ZYPinYinSearch.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | 1A8BECF1-875F-4B3B-9F01-71209E50540C 9 | IDESourceControlProjectName 10 | ZYPinYinSearch 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 2E026F72F9604621FB8A87573F4C9D4B147E0F25 14 | https://github.com/bjzhangyang/ZYPinYinSearch.git 15 | 16 | IDESourceControlProjectPath 17 | ZYPinYinSearch.xcodeproj 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | 2E026F72F9604621FB8A87573F4C9D4B147E0F25 21 | ../..ZYPinYinSearch/ 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/bjzhangyang/ZYPinYinSearch.git 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | 2E026F72F9604621FB8A87573F4C9D4B147E0F25 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | 2E026F72F9604621FB8A87573F4C9D4B147E0F25 36 | IDESourceControlWCCName 37 | ZYPinYinSearch 38 | 39 | 40 | IDESourceControlRepositoryExtensionIdentifierKey 41 | public.vcs.git 42 | IDESourceControlWCCIdentifierKey 43 | 2E026F72F9604621FB8A87573F4C9D4B147E0F25 44 | IDESourceControlWCCName 45 | ZYPinYinSearch 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /ZYPinYinSearch.xcodeproj/project.xcworkspace/xcuserdata/soufun.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bjzhangyang/ZYPinYinSearch/d915edc23dd4c7201b18a256bd38969907b6733a/ZYPinYinSearch.xcodeproj/project.xcworkspace/xcuserdata/soufun.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /ZYPinYinSearch.xcodeproj/xcuserdata/soufun.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /ZYPinYinSearch.xcodeproj/xcuserdata/soufun.xcuserdatad/xcschemes/ZYPinYinSearch.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 76 | 78 | 84 | 85 | 86 | 87 | 88 | 89 | 95 | 97 | 103 | 104 | 105 | 106 | 108 | 109 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /ZYPinYinSearch.xcodeproj/xcuserdata/soufun.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | ZYPinYinSearch.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 5AE26F8A1B65C6AE008C06ED 16 | 17 | primary 18 | 19 | 20 | 5AE26FA31B65C6AE008C06ED 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /ZYPinYinSearch/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // ZYPinYinSearch 4 | // 5 | // Created by soufun on 15/7/27. 6 | // Copyright (c) 2015年 ZY. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /ZYPinYinSearch/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // ZYPinYinSearch 4 | // 5 | // Created by soufun on 15/7/27. 6 | // Copyright (c) 2015年 ZY. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /ZYPinYinSearch/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /ZYPinYinSearch/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 29 | 39 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /ZYPinYinSearch/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /ZYPinYinSearch/Images.xcassets/backArrow.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x", 6 | "filename" : "backArrow.png" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /ZYPinYinSearch/Images.xcassets/backArrow.imageset/backArrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bjzhangyang/ZYPinYinSearch/d915edc23dd4c7201b18a256bd38969907b6733a/ZYPinYinSearch/Images.xcassets/backArrow.imageset/backArrow.png -------------------------------------------------------------------------------- /ZYPinYinSearch/Images.xcassets/searchButton.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x", 6 | "filename" : "searchButton.png" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /ZYPinYinSearch/Images.xcassets/searchButton.imageset/searchButton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bjzhangyang/ZYPinYinSearch/d915edc23dd4c7201b18a256bd38969907b6733a/ZYPinYinSearch/Images.xcassets/searchButton.imageset/searchButton.png -------------------------------------------------------------------------------- /ZYPinYinSearch/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | ZY.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 2.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /ZYPinYinSearch/Person.h: -------------------------------------------------------------------------------- 1 | // 2 | // Person.h 3 | // ZYPinYinSearch 4 | // 5 | // Created by soufun on 15/7/27. 6 | // Copyright (c) 2015年 ZY. All rights reserved. 7 | // 8 | 9 | #import 10 | @interface Person : NSObject 11 | @property (nonatomic,copy)NSString * name; 12 | @property (nonatomic,copy)NSString * nickname; 13 | @property (nonatomic,copy)NSString * age; 14 | +(Person *)CreatePersonWithName:(NSString*)name andNickname:(NSString*)nickname; 15 | @end 16 | -------------------------------------------------------------------------------- /ZYPinYinSearch/Person.m: -------------------------------------------------------------------------------- 1 | 2 | 3 | // 4 | // Person.m 5 | // ZYPinYinSearch 6 | // 7 | // Created by soufun on 15/7/27. 8 | // Copyright (c) 2015年 ZY. All rights reserved. 9 | // 10 | 11 | #import "Person.h" 12 | 13 | @implementation Person 14 | +(Person *)CreatePersonWithName:(NSString*)name andNickname:(NSString*)nickname{ 15 | Person * person = [[Person alloc]init]; 16 | person.name = name; 17 | person.nickname = nickname; 18 | return person; 19 | } 20 | @end 21 | -------------------------------------------------------------------------------- /ZYPinYinSearch/PrefixHeader.pch: -------------------------------------------------------------------------------- 1 | // 2 | // PrefixHeader.pch 3 | // ZYPinYinSearch 4 | // 5 | // Created by soufun on 15/7/27. 6 | // Copyright (c) 2015年 ZY. All rights reserved. 7 | // 8 | #import 9 | #define kWidth [UIScreen mainScreen].bounds.size.width 10 | #define kHight [UIScreen mainScreen].bounds.size.height 11 | #ifndef ZYPinYinSearch_PrefixHeader_pch 12 | #define ZYPinYinSearch_PrefixHeader_pch 13 | 14 | // Include any system framework and library headers here that should be included in all compilation units. 15 | // You will also need to set the Prefix Header build setting of one or more of your targets to reference this file. 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /ZYPinYinSearch/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // ZYPinYinSearch 4 | // 5 | // Created by soufun on 15/7/27. 6 | // Copyright (c) 2015年 ZY. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /ZYPinYinSearch/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // ZYPinYinSearch 4 | // 5 | // Created by soufun on 15/7/27. 6 | // Copyright (c) 2015年 ZY. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "ZYSearchViewController.h" 11 | #import "ZYPinYinSearch.h" 12 | @interface ViewController () 13 | 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | UIView * tempView = [[UIView alloc]initWithFrame:CGRectZero]; 21 | [self.view addSubview:tempView]; 22 | self.view.backgroundColor = [UIColor colorWithRed:26/255.0 green:61/255.0 blue:89/255.0 alpha:1]; 23 | self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque; 24 | //处理多音字,指定词组的拼音,指定一次,整个APP运行过程中都有效,可以手动清除 25 | [ZYPinYinSearch setupReplacement:^NSDictionary *{ 26 | return @{@"长春":@"changchun",@"重庆":@"chongqing"};//长春默认是"zhangchun",所以咱们这里可以特殊设置成"changchun" 27 | }]; 28 | // Do any additional setup after loading the view, typically from a nib. 29 | } 30 | - (IBAction)buttonClicked:(UIButton *)sender { 31 | NSString * type; 32 | switch (sender.tag) { 33 | case 1: 34 | type = @"字符串"; 35 | break; 36 | case 2: 37 | type = @"字典"; 38 | break; 39 | case 3: 40 | type = @"Model"; 41 | break; 42 | default: 43 | break; 44 | } 45 | [self performSegueWithIdentifier:@"push" sender:type]; 46 | } 47 | -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ 48 | ZYSearchViewController * target = [segue destinationViewController]; 49 | target.type = sender; 50 | } 51 | - (void)didReceiveMemoryWarning { 52 | [super didReceiveMemoryWarning]; 53 | // Dispose of any resources that can be recreated. 54 | } 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /ZYPinYinSearch/ZYPinYinSearchLib/ChineseInclude.h: -------------------------------------------------------------------------------- 1 | // 2 | // ChineseInclude.h 3 | // Search 4 | // 5 | // Created by LYZ on 14-1-24. 6 | // Copyright (c) 2014年 LYZ. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ChineseInclude : NSObject 12 | + (BOOL)isIncludeChineseInString:(NSString*)str; 13 | @end 14 | -------------------------------------------------------------------------------- /ZYPinYinSearch/ZYPinYinSearchLib/ChineseInclude.m: -------------------------------------------------------------------------------- 1 | // 2 | // ChineseInclude.m 3 | // Search 4 | // 5 | // Created by LYZ on 14-1-24. 6 | // Copyright (c) 2014年 LYZ. All rights reserved. 7 | // 8 | 9 | #import "ChineseInclude.h" 10 | 11 | @implementation ChineseInclude 12 | + (BOOL)isIncludeChineseInString:(NSString*)str { 13 | for (int i=0; i 10 | @class NSArray; 11 | @class NSMutableDictionary; 12 | 13 | @interface ChineseToPinyinResource : NSObject { 14 | NSString* _directory; 15 | NSDictionary *_unicodeToHanyuPinyinTable; 16 | } 17 | //@property(nonatomic, strong)NSDictionary *unicodeToHanyuPinyinTable; 18 | 19 | - (id)init; 20 | - (void)initializeResource; 21 | - (NSArray *)getHanyuPinyinStringArrayWithChar:(unichar)ch; 22 | - (BOOL)isValidRecordWithNSString:(NSString *)record; 23 | - (NSString *)getHanyuPinyinRecordFromCharWithChar:(unichar)ch; 24 | + (ChineseToPinyinResource *)getInstance; 25 | 26 | @end 27 | 28 | 29 | 30 | #endif // _ChineseToPinyinResource_H_ 31 | -------------------------------------------------------------------------------- /ZYPinYinSearch/ZYPinYinSearchLib/ChineseToPinyinResource.m: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by kimziv on 13-9-14. 5 | // 6 | 7 | #include "ChineseToPinyinResource.h" 8 | #define LEFT_BRACKET @"(" 9 | #define RIGHT_BRACKET @")" 10 | #define COMMA @"," 11 | 12 | #define kCacheKeyForUnicode2Pinyin @"cache.key.for.unicode.to.pinyin" 13 | 14 | static inline NSString* cachePathForKey(NSString* directory, NSString* key) { 15 | return [directory stringByAppendingPathComponent:key]; 16 | } 17 | 18 | @interface ChineseToPinyinResource () 19 | - (id)cachedObjectForKey:(NSString*)key; 20 | -(void)cacheObjec:(id)obj forKey:(NSString *)key; 21 | 22 | @end 23 | 24 | @implementation ChineseToPinyinResource 25 | //@synthesize unicodeToHanyuPinyinTable=_unicodeToHanyuPinyinTable; 26 | //- (NSDictionary *)getUnicodeToHanyuPinyinTable { 27 | // return _unicodeToHanyuPinyinTable; 28 | //} 29 | 30 | - (id)init { 31 | if (self = [super init]) { 32 | _unicodeToHanyuPinyinTable = nil; 33 | [self initializeResource]; 34 | } 35 | return self; 36 | } 37 | 38 | - (void)initializeResource { 39 | NSString* cachesDirectory = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0]; 40 | NSString* oldCachesDirectory = [[[cachesDirectory stringByAppendingPathComponent:[[NSProcessInfo processInfo] processName]] stringByAppendingPathComponent:@"PinYinCache"] copy]; 41 | 42 | if([[NSFileManager defaultManager] fileExistsAtPath:oldCachesDirectory]) { 43 | [[NSFileManager defaultManager] removeItemAtPath:oldCachesDirectory error:NULL]; 44 | } 45 | 46 | _directory = [[[cachesDirectory stringByAppendingPathComponent:[[NSBundle mainBundle] bundleIdentifier]] stringByAppendingPathComponent:@"PinYinCache"] copy]; 47 | 48 | NSDictionary *dataMap=(NSDictionary *)[self cachedObjectForKey:kCacheKeyForUnicode2Pinyin]; 49 | if (dataMap) { 50 | self->_unicodeToHanyuPinyinTable=dataMap; 51 | }else{ 52 | NSString *resourceName =[[NSBundle mainBundle] pathForResource:@"unicode_to_hanyu_pinyin" ofType:@"txt"]; 53 | NSString *dictionaryText=[NSString stringWithContentsOfFile:resourceName encoding:NSUTF8StringEncoding error:nil]; 54 | NSArray *lines = [dictionaryText componentsSeparatedByString:@"\r\n"]; 55 | __block NSMutableDictionary *tempMap=[[NSMutableDictionary alloc] init]; 56 | @autoreleasepool { 57 | [lines enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 58 | NSArray *lineComponents=[obj componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 59 | //NSLog(@"%@, %@",lineComponents[0],lineComponents[1]); 60 | [tempMap setObject:lineComponents[1] forKey:lineComponents[0]]; 61 | }]; 62 | } 63 | self->_unicodeToHanyuPinyinTable=tempMap; 64 | [self cacheObjec:self->_unicodeToHanyuPinyinTable forKey:kCacheKeyForUnicode2Pinyin]; 65 | } 66 | } 67 | 68 | - (id)cachedObjectForKey:(NSString*)key 69 | { 70 | NSData *data = [NSData dataWithContentsOfFile:cachePathForKey(_directory, key) options:0 error:NULL]; 71 | if (data) { 72 | return [NSKeyedUnarchiver unarchiveObjectWithData:data]; 73 | } 74 | return nil; 75 | } 76 | 77 | -(void)cacheObjec:(id)obj forKey:(NSString *)key 78 | { 79 | NSData* data= [NSKeyedArchiver archivedDataWithRootObject:obj]; 80 | NSString* cachePath = cachePathForKey(_directory, key); 81 | dispatch_async(dispatch_get_main_queue(), ^{ 82 | [data writeToFile:cachePath atomically:YES]; 83 | }); 84 | } 85 | 86 | - (NSArray *)getHanyuPinyinStringArrayWithChar:(unichar)ch { 87 | NSString *pinyinRecord = [self getHanyuPinyinRecordFromCharWithChar:ch]; 88 | if (nil != pinyinRecord) { 89 | NSRange rangeOfLeftBracket= [pinyinRecord rangeOfString:LEFT_BRACKET]; 90 | NSRange rangeOfRightBracket= [pinyinRecord rangeOfString:RIGHT_BRACKET]; 91 | NSString *stripedString = [pinyinRecord substringWithRange:NSMakeRange(rangeOfLeftBracket.location+rangeOfLeftBracket.length, rangeOfRightBracket.location-rangeOfLeftBracket.location-rangeOfLeftBracket.length)]; 92 | return [stripedString componentsSeparatedByString:COMMA]; 93 | } 94 | else return nil; 95 | } 96 | 97 | - (BOOL)isValidRecordWithNSString:(NSString *)record { 98 | NSString *noneStr = @"(none0)"; 99 | if ((nil != record) && ![record isEqual:noneStr] && [record hasPrefix:LEFT_BRACKET] && [record hasSuffix:RIGHT_BRACKET]) { 100 | return YES; 101 | } 102 | else return NO; 103 | } 104 | 105 | - (NSString *)getHanyuPinyinRecordFromCharWithChar:(unichar)ch { 106 | int codePointOfChar = ch; 107 | NSString *codepointHexStr =[[NSString stringWithFormat:@"%x", codePointOfChar] uppercaseString]; 108 | NSString *foundRecord =[self->_unicodeToHanyuPinyinTable objectForKey:codepointHexStr]; 109 | return [self isValidRecordWithNSString:foundRecord] ? foundRecord : nil; 110 | } 111 | 112 | + (ChineseToPinyinResource *)getInstance { 113 | static ChineseToPinyinResource *sharedInstance=nil; 114 | static dispatch_once_t onceToken; 115 | dispatch_once(&onceToken, ^{ 116 | sharedInstance=[[self alloc] init]; 117 | }); 118 | return sharedInstance; 119 | } 120 | 121 | @end 122 | 123 | -------------------------------------------------------------------------------- /ZYPinYinSearch/ZYPinYinSearchLib/HanyuPinyinOutputFormat.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by kimziv on 13-9-14. 3 | */ 4 | #ifndef _HanyuPinyinOutputFormat_H_ 5 | #define _HanyuPinyinOutputFormat_H_ 6 | #import 7 | typedef enum { 8 | ToneTypeWithToneNumber, 9 | ToneTypeWithoutTone, 10 | ToneTypeWithToneMark 11 | }ToneType; 12 | 13 | typedef enum { 14 | CaseTypeUppercase, 15 | CaseTypeLowercase 16 | }CaseType; 17 | 18 | typedef enum { 19 | VCharTypeWithUAndColon, 20 | VCharTypeWithV, 21 | VCharTypeWithUUnicode 22 | }VCharType; 23 | 24 | 25 | @interface HanyuPinyinOutputFormat : NSObject 26 | 27 | @property(nonatomic, assign) VCharType vCharType; 28 | @property(nonatomic, assign) CaseType caseType; 29 | @property(nonatomic, assign) ToneType toneType; 30 | 31 | - (id)init; 32 | - (void)restoreDefault; 33 | @end 34 | 35 | #endif // _HanyuPinyinOutputFormat_H_ 36 | -------------------------------------------------------------------------------- /ZYPinYinSearch/ZYPinYinSearchLib/HanyuPinyinOutputFormat.m: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by kimziv on 13-9-14. 5 | // 6 | 7 | #include "HanyuPinyinOutputFormat.h" 8 | 9 | @implementation HanyuPinyinOutputFormat 10 | @synthesize vCharType=_vCharType; 11 | @synthesize caseType=_caseType; 12 | @synthesize toneType=_toneType; 13 | 14 | - (id)init { 15 | if (self = [super init]) { 16 | [self restoreDefault]; 17 | } 18 | return self; 19 | } 20 | 21 | - (void)restoreDefault { 22 | _vCharType = VCharTypeWithUAndColon; 23 | _caseType = CaseTypeLowercase; 24 | _toneType = ToneTypeWithToneNumber; 25 | } 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /ZYPinYinSearch/ZYPinYinSearchLib/NSString+PinYin4Cocoa.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+PinYin4Cocoa.h 3 | // PinYin4Cocoa 4 | // 5 | // Created by kimziv on 13-9-15. 6 | // Copyright (c) 2013年 kimziv. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSString (PinYin4Cocoa) 12 | 13 | - (NSInteger)indexOfString:(NSString *)s; 14 | - (NSInteger)indexOfString:(NSString *)s fromIndex:(int)index; 15 | - (NSInteger)indexOf:(int)ch; 16 | - (NSInteger)indexOf:(int)ch fromIndex:(int)index; 17 | + (NSString *)valueOfChar:(unichar)value; 18 | 19 | -(NSString *) stringByReplacingRegexPattern:(NSString *)regex withString:(NSString *) replacement; 20 | -(NSString *) stringByReplacingRegexPattern:(NSString *)regex withString:(NSString *) replacement caseInsensitive:(BOOL) ignoreCase; 21 | -(NSString *) stringByReplacingRegexPattern:(NSString *)regex withString:(NSString *) replacement caseInsensitive:(BOOL) ignoreCase treatAsOneLine:(BOOL) assumeMultiLine; 22 | -(NSArray *) stringsByExtractingGroupsUsingRegexPattern:(NSString *)regex; 23 | -(NSArray *) stringsByExtractingGroupsUsingRegexPattern:(NSString *)regex caseInsensitive:(BOOL) ignoreCase treatAsOneLine:(BOOL) assumeMultiLine; 24 | -(BOOL) matchesPatternRegexPattern:(NSString *)regex; 25 | -(BOOL) matchesPatternRegexPattern:(NSString *)regex caseInsensitive:(BOOL) ignoreCase treatAsOneLine:(BOOL) assumeMultiLine; 26 | @end 27 | -------------------------------------------------------------------------------- /ZYPinYinSearch/ZYPinYinSearchLib/NSString+PinYin4Cocoa.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+PinYin4Cocoa.m 3 | // PinYin4Cocoa 4 | // 5 | // Created by kimziv on 13-9-15. 6 | // Copyright (c) 2013年 kimziv. All rights reserved. 7 | // 8 | 9 | #import "NSString+PinYin4Cocoa.h" 10 | 11 | @implementation NSString (PinYin4Cocoa) 12 | 13 | 14 | - (NSInteger)indexOfString:(NSString *)s { 15 | NSAssert3((s!=nil), @"Error, s is a nil string, %s, %s, %d", __FILE__, __FUNCTION__, __LINE__); 16 | if ([s length] == 0) { 17 | return 0; 18 | } 19 | NSRange range = [self rangeOfString:s]; 20 | return range.location == NSNotFound ? -1 : (int) range.location; 21 | } 22 | 23 | 24 | - (NSInteger)indexOfString:(NSString *)s fromIndex:(int)index { 25 | NSAssert3((s!=nil), @"Error, s is a nil string, %s, %s, %d", __FILE__, __FUNCTION__, __LINE__); 26 | if ([s length] == 0) { 27 | return 0; 28 | } 29 | NSRange searchRange = NSMakeRange((NSUInteger) index, 30 | [self length] - (NSUInteger) index); 31 | NSRange range = [self rangeOfString:s 32 | options:NSLiteralSearch 33 | range:searchRange]; 34 | return range.location == NSNotFound ? -1 : (int) range.location; 35 | } 36 | 37 | - (NSInteger)indexOf:(int)ch { 38 | // unichar c = (unichar) ch; 39 | // for(int i=0;i 0); 133 | } 134 | 135 | -(BOOL) matchesPatternRegexPattern:(NSString *)regex { 136 | return [self matchesPatternRegexPattern:regex caseInsensitive:NO treatAsOneLine:NO]; 137 | } 138 | 139 | @end 140 | -------------------------------------------------------------------------------- /ZYPinYinSearch/ZYPinYinSearchLib/PinYinForObjc.h: -------------------------------------------------------------------------------- 1 | // 2 | // PinYinForObjc.h 3 | // Search 4 | // 5 | // Created by LYZ on 14-1-24. 6 | // Copyright (c) 2014年 LYZ. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "HanyuPinyinOutputFormat.h" 11 | #import "PinyinHelper.h" 12 | 13 | @interface PinYinForObjc : NSObject 14 | 15 | + (NSString*)chineseConvertToPinYin:(NSString*)chinese;//转换为拼音 16 | + (NSString*)chineseConvertToPinYinHead:(NSString *)chinese;//转换为拼音首字母 17 | @end 18 | -------------------------------------------------------------------------------- /ZYPinYinSearch/ZYPinYinSearchLib/PinYinForObjc.m: -------------------------------------------------------------------------------- 1 | // 2 | // PinYinForObjc.m 3 | // Search 4 | // 5 | // Created by LYZ on 14-1-24. 6 | // Copyright (c) 2014年 LYZ. All rights reserved. 7 | // 8 | 9 | #import "PinYinForObjc.h" 10 | 11 | @implementation PinYinForObjc 12 | 13 | + (NSString*)chineseConvertToPinYin:(NSString*)chinese { 14 | NSString *sourceText = chinese; 15 | HanyuPinyinOutputFormat *outputFormat = [[HanyuPinyinOutputFormat alloc] init]; 16 | [outputFormat setToneType:ToneTypeWithoutTone]; 17 | [outputFormat setVCharType:VCharTypeWithV]; 18 | [outputFormat setCaseType:CaseTypeLowercase]; 19 | NSString *outputPinyin = [PinyinHelper toHanyuPinyinStringWithNSString:sourceText withHanyuPinyinOutputFormat:outputFormat withNSString:@""]; 20 | 21 | return outputPinyin; 22 | 23 | 24 | } 25 | 26 | + (NSString*)chineseConvertToPinYinHead:(NSString *)chinese { 27 | HanyuPinyinOutputFormat *outputFormat = [[HanyuPinyinOutputFormat alloc] init]; 28 | [outputFormat setToneType:ToneTypeWithoutTone]; 29 | [outputFormat setVCharType:VCharTypeWithV]; 30 | [outputFormat setCaseType:CaseTypeLowercase]; 31 | NSMutableString *outputPinyin = [[NSMutableString alloc] init]; 32 | for (int i=0;i 10 | @class HanyuPinyinOutputFormat; 11 | 12 | @interface PinyinFormatter : NSObject { 13 | } 14 | 15 | + (NSString *)formatHanyuPinyinWithNSString:(NSString *)pinyinStr 16 | withHanyuPinyinOutputFormat:(HanyuPinyinOutputFormat *)outputFormat; 17 | + (NSString *)convertToneNumber2ToneMarkWithNSString:(NSString *)pinyinStr; 18 | - (id)init; 19 | @end 20 | 21 | #endif // _PinyinFormatter_H_ 22 | -------------------------------------------------------------------------------- /ZYPinYinSearch/ZYPinYinSearchLib/PinyinFormatter.m: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by kimziv on 13-9-14. 5 | // 6 | 7 | #include "HanyuPinyinOutputFormat.h" 8 | #include "PinyinFormatter.h" 9 | #import "NSString+PinYin4Cocoa.h" 10 | 11 | @interface PinyinFormatter () 12 | +(NSInteger)getNumericValue:(unichar)c; 13 | +(NSInteger)indexOfChar:(int*) table ch:(unichar)c; 14 | @end 15 | 16 | @implementation PinyinFormatter 17 | 18 | static int numericKeys[] = { 19 | 0x0030, 0x0041, 0x0061, 0x00b2, 0x00b9, 0x00bc, 0x0660, 0x06f0, 20 | 0x0966, 0x09e6, 0x09f4, 0x09f9, 0x0a66, 0x0ae6, 0x0b66, 0x0be7, 21 | 0x0bf1, 0x0bf2, 0x0c66, 0x0ce6, 0x0d66, 0x0e50, 0x0ed0, 0x0f20, 22 | 0x1040, 0x1369, 0x1373, 0x1374, 0x1375, 0x1376, 0x1377, 0x1378, 23 | 0x1379, 0x137a, 0x137b, 0x137c, 0x16ee, 0x17e0, 0x1810, 0x2070, 24 | 0x2074, 0x2080, 0x2153, 0x215f, 0x2160, 0x216c, 0x216d, 0x216e, 25 | 0x216f, 0x2170, 0x217c, 0x217d, 0x217e, 0x217f, 0x2180, 0x2181, 26 | 0x2182, 0x2460, 0x2474, 0x2488, 0x24ea, 0x2776, 0x2780, 0x278a, 27 | 0x3007, 0x3021, 0x3038, 0x3039, 0x303a, 0x3280, 0xff10, 0xff21, 28 | 0xff41, 29 | }; 30 | 31 | static unichar numericValues[] = { 32 | 0x0039, 0x0030, 0x005a, 0x0037, 0x007a, 0x0057, 0x00b3, 0x00b0, 33 | 0x00b9, 0x00b8, 0x00be, 0x0000, 0x0669, 0x0660, 0x06f9, 0x06f0, 34 | 0x096f, 0x0966, 0x09ef, 0x09e6, 0x09f7, 0x09f3, 0x09f9, 0x09e9, 35 | 0x0a6f, 0x0a66, 0x0aef, 0x0ae6, 0x0b6f, 0x0b66, 0x0bf0, 0x0be6, 36 | 0x0bf1, 0x0b8d, 0x0bf2, 0x080a, 0x0c6f, 0x0c66, 0x0cef, 0x0ce6, 37 | 0x0d6f, 0x0d66, 0x0e59, 0x0e50, 0x0ed9, 0x0ed0, 0x0f29, 0x0f20, 38 | 0x1049, 0x1040, 0x1372, 0x1368, 0x1373, 0x135f, 0x1374, 0x1356, 39 | 0x1375, 0x134d, 0x1376, 0x1344, 0x1377, 0x133b, 0x1378, 0x1332, 40 | 0x1379, 0x1329, 0x137a, 0x1320, 0x137b, 0x1317, 0x137c, 0xec6c, 41 | 0x16f0, 0x16dd, 0x17e9, 0x17e0, 0x1819, 0x1810, 0x2070, 0x2070, 42 | 0x2079, 0x2070, 0x2089, 0x2080, 0x215e, 0x0000, 0x215f, 0x215e, 43 | 0x216b, 0x215f, 0x216c, 0x213a, 0x216d, 0x2109, 0x216e, 0x1f7a, 44 | 0x216f, 0x1d87, 0x217b, 0x216f, 0x217c, 0x214a, 0x217d, 0x2119, 45 | 0x217e, 0x1f8a, 0x217f, 0x1d97, 0x2180, 0x1d98, 0x2181, 0x0df9, 46 | 0x2182, 0xfa72, 0x2473, 0x245f, 0x2487, 0x2473, 0x249b, 0x2487, 47 | 0x24ea, 0x24ea, 0x277f, 0x2775, 0x2789, 0x277f, 0x2793, 0x2789, 48 | 0x3007, 0x3007, 0x3029, 0x3020, 0x3038, 0x302e, 0x3039, 0x3025, 49 | 0x303a, 0x301c, 0x3289, 0x327f, 0xff19, 0xff10, 0xff3a, 0xff17, 50 | 0xff5a, 0xff37, 51 | }; 52 | 53 | 54 | + (NSString *)formatHanyuPinyinWithNSString:(NSString *)pinyinStr 55 | withHanyuPinyinOutputFormat:(HanyuPinyinOutputFormat *)outputFormat { 56 | if ((ToneTypeWithToneMark == [outputFormat toneType]) && ((VCharTypeWithV == [outputFormat vCharType]) || (VCharTypeWithUAndColon == [outputFormat vCharType]))) { 57 | @throw [NSException exceptionWithName:@"Throwing a BadHanyuPinyinOutputFormatCombination exception" reason:@"tone marks cannot be added to v or u:." userInfo:nil]; 58 | } 59 | if (ToneTypeWithoutTone == [outputFormat toneType]) { 60 | pinyinStr =[pinyinStr stringByReplacingOccurrencesOfString:@"[1-5]" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, pinyinStr.length)]; 61 | } 62 | else if (ToneTypeWithToneMark == [outputFormat toneType]) { 63 | pinyinStr =[pinyinStr stringByReplacingOccurrencesOfString:@"u:" withString:@"v"]; 64 | pinyinStr = [PinyinFormatter convertToneNumber2ToneMarkWithNSString:pinyinStr]; 65 | } 66 | if (VCharTypeWithV == [outputFormat vCharType]) { 67 | pinyinStr =[pinyinStr stringByReplacingOccurrencesOfString:@"u:" withString:@"v"]; 68 | } 69 | else if (VCharTypeWithUUnicode == [outputFormat vCharType]) { 70 | pinyinStr =[pinyinStr stringByReplacingOccurrencesOfString:@"u:" withString:@"ü"]; 71 | } 72 | if (CaseTypeUppercase == [outputFormat caseType]) { 73 | pinyinStr = [pinyinStr uppercaseString]; 74 | } 75 | return pinyinStr; 76 | } 77 | 78 | + (NSString *)convertToneNumber2ToneMarkWithNSString:(NSString *)pinyinStr { 79 | NSString *lowerCasePinyinStr = [pinyinStr lowercaseString]; 80 | if ([lowerCasePinyinStr matchesPatternRegexPattern:@"[a-z]*[1-5]?"]) { 81 | unichar defautlCharValue = '$'; 82 | int defautlIndexValue = -1; 83 | unichar unmarkedVowel = defautlCharValue; 84 | int indexOfUnmarkedVowel = defautlIndexValue; 85 | unichar charA = 'a'; 86 | unichar charE = 'e'; 87 | NSString *ouStr = @"ou"; 88 | NSString *allUnmarkedVowelStr = @"aeiouv"; 89 | NSString *allMarkedVowelStr = @"āáăàaēéĕèeīíĭìiōóŏòoūúŭùuǖǘǚǜü"; 90 | if ([lowerCasePinyinStr matchesPatternRegexPattern:@"[a-z]*[1-5]"]) { 91 | int tuneNumber = [PinyinFormatter getNumericValue:[lowerCasePinyinStr characterAtIndex:lowerCasePinyinStr.length -1]]; 92 | int indexOfA = [lowerCasePinyinStr indexOf:charA]; 93 | int indexOfE = [lowerCasePinyinStr indexOf:charE]; 94 | int ouIndex = [lowerCasePinyinStr indexOfString:ouStr]; 95 | if (-1 != indexOfA) { 96 | indexOfUnmarkedVowel = indexOfA; 97 | unmarkedVowel = charA; 98 | } 99 | else if (-1 != indexOfE) { 100 | indexOfUnmarkedVowel = indexOfE; 101 | unmarkedVowel = charE; 102 | } 103 | else if (-1 != ouIndex) { 104 | indexOfUnmarkedVowel = ouIndex; 105 | unmarkedVowel = [ouStr characterAtIndex:0]; 106 | } 107 | else { 108 | for (int i = [lowerCasePinyinStr length] - 1; i >= 0; i--) { 109 | if ([[NSString valueOfChar:[lowerCasePinyinStr characterAtIndex:i]] matchesPatternRegexPattern:@"[aeiouv]"]) { 110 | indexOfUnmarkedVowel = i; 111 | unmarkedVowel = [lowerCasePinyinStr characterAtIndex:i]; 112 | break; 113 | } 114 | } 115 | } 116 | if ((defautlCharValue != unmarkedVowel) && (defautlIndexValue != indexOfUnmarkedVowel)) { 117 | int rowIndex = [allUnmarkedVowelStr indexOf:unmarkedVowel]; 118 | int columnIndex = tuneNumber - 1; 119 | int vowelLocation = rowIndex * 5 + columnIndex; 120 | unichar markedVowel = [allMarkedVowelStr characterAtIndex:vowelLocation]; 121 | NSMutableString *resultBuffer = [[NSMutableString alloc] init]; 122 | [resultBuffer appendString:[[lowerCasePinyinStr substringToIndex:indexOfUnmarkedVowel+1] stringByReplacingOccurrencesOfString:@"v" withString:@"ü"]]; 123 | [resultBuffer appendFormat:@"%C",markedVowel]; 124 | [resultBuffer appendString:[[lowerCasePinyinStr substringWithRange:NSMakeRange(indexOfUnmarkedVowel + 1, lowerCasePinyinStr.length-indexOfUnmarkedVowel)] stringByReplacingOccurrencesOfString:@"v" withString:@"ü"]]; 125 | return [resultBuffer description]; 126 | } 127 | else { 128 | return lowerCasePinyinStr; 129 | } 130 | } 131 | else { 132 | return [lowerCasePinyinStr stringByReplacingOccurrencesOfString:@"v" withString:@"ü"]; 133 | } 134 | } 135 | else { 136 | return lowerCasePinyinStr; 137 | } 138 | } 139 | 140 | +(NSInteger)getNumericValue:(unichar)c 141 | { 142 | if (c < 128) { 143 | // Optimized for ASCII 144 | if (c >= '0' && c <= '9') { 145 | return c - '0'; 146 | } 147 | if (c >= 'a' && c <= 'z') { 148 | return c - ('a' - 10); 149 | } 150 | if (c >= 'A' && c <= 'Z') { 151 | return c - ('A' - 10); 152 | } 153 | return -1; 154 | } 155 | NSInteger result = [self indexOfChar:numericKeys ch:c]; 156 | if (result >= 0 && c <= numericValues[result * 2]) { 157 | unichar difference = numericValues[result * 2 + 1]; 158 | if (difference == 0) { 159 | return -2; 160 | } 161 | // Value is always positive, must be negative value 162 | if (difference > c) { 163 | return c - (short) difference; 164 | } 165 | return c - difference; 166 | } 167 | return -1; 168 | 169 | } 170 | 171 | +(NSInteger)indexOfChar:(int*) table ch:(unichar)c{ 172 | NSInteger len=sizeof(table)/sizeof(table[0]); 173 | for (int i = 0; i < len; i++) { 174 | if (table[i] == (int) c) { 175 | return i; 176 | } 177 | } 178 | return -1; 179 | } 180 | 181 | 182 | - (id)init { 183 | return [super init]; 184 | } 185 | 186 | 187 | 188 | @end 189 | -------------------------------------------------------------------------------- /ZYPinYinSearch/ZYPinYinSearchLib/PinyinHelper.h: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by kimziv on 13-9-14. 5 | // 6 | 7 | #ifndef _PinyinHelper_H_ 8 | #define _PinyinHelper_H_ 9 | #import 10 | @class HanyuPinyinOutputFormat; 11 | 12 | @interface PinyinHelper : NSObject { 13 | } 14 | 15 | + (NSArray *)toHanyuPinyinStringArrayWithChar:(unichar)ch; 16 | + (NSArray *)toHanyuPinyinStringArrayWithChar:(unichar)ch 17 | withHanyuPinyinOutputFormat:(HanyuPinyinOutputFormat *)outputFormat; 18 | + (NSArray *)getFormattedHanyuPinyinStringArrayWithChar:(unichar)ch 19 | withHanyuPinyinOutputFormat:(HanyuPinyinOutputFormat *)outputFormat; 20 | + (NSArray *)getUnformattedHanyuPinyinStringArrayWithChar:(unichar)ch; 21 | + (NSArray *)toTongyongPinyinStringArrayWithChar:(unichar)ch; 22 | + (NSArray *)toWadeGilesPinyinStringArrayWithChar:(unichar)ch; 23 | + (NSArray *)toMPS2PinyinStringArrayWithChar:(unichar)ch; 24 | + (NSArray *)toYalePinyinStringArrayWithChar:(unichar)ch; 25 | + (NSArray *)convertToTargetPinyinStringArrayWithChar:(unichar)ch 26 | withPinyinRomanizationType:(NSString *)targetPinyinSystem; 27 | + (NSArray *)toGwoyeuRomatzyhStringArrayWithChar:(unichar)ch; 28 | + (NSArray *)convertToGwoyeuRomatzyhStringArrayWithChar:(unichar)ch; 29 | + (NSString *)toHanyuPinyinStringWithNSString:(NSString *)str 30 | withHanyuPinyinOutputFormat:(HanyuPinyinOutputFormat *)outputFormat 31 | withNSString:(NSString *)seperater; 32 | + (NSString *)getFirstHanyuPinyinStringWithChar:(unichar)ch 33 | withHanyuPinyinOutputFormat:(HanyuPinyinOutputFormat *)outputFormat; 34 | - (id)init; 35 | @end 36 | 37 | #endif // _PinyinHelper_H_ 38 | -------------------------------------------------------------------------------- /ZYPinYinSearch/ZYPinYinSearchLib/PinyinHelper.m: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | // Created by kimziv on 13-9-14. 5 | // 6 | 7 | #include "ChineseToPinyinResource.h" 8 | #include "HanyuPinyinOutputFormat.h" 9 | #include "PinyinFormatter.h" 10 | #include "PinyinHelper.h" 11 | 12 | #define HANYU_PINYIN @"Hanyu" 13 | #define WADEGILES_PINYIN @"Wade" 14 | #define MPS2_PINYIN @"MPSII" 15 | #define YALE_PINYIN @"Yale" 16 | #define TONGYONG_PINYIN @"Tongyong" 17 | #define GWOYEU_ROMATZYH @"Gwoyeu" 18 | 19 | @implementation PinyinHelper 20 | 21 | + (NSArray *)toHanyuPinyinStringArrayWithChar:(unichar)ch { 22 | return [PinyinHelper getUnformattedHanyuPinyinStringArrayWithChar:ch]; 23 | } 24 | 25 | + (NSArray *)toHanyuPinyinStringArrayWithChar:(unichar)ch 26 | withHanyuPinyinOutputFormat:(HanyuPinyinOutputFormat *)outputFormat { 27 | return [PinyinHelper getFormattedHanyuPinyinStringArrayWithChar:ch withHanyuPinyinOutputFormat:outputFormat]; 28 | } 29 | 30 | + (NSArray *)getFormattedHanyuPinyinStringArrayWithChar:(unichar)ch 31 | withHanyuPinyinOutputFormat:(HanyuPinyinOutputFormat *)outputFormat { 32 | NSMutableArray *pinyinStrArray =[NSMutableArray arrayWithArray:[PinyinHelper getUnformattedHanyuPinyinStringArrayWithChar:ch]]; 33 | if (nil != pinyinStrArray) { 34 | for (int i = 0; i < (int) [pinyinStrArray count]; i++) { 35 | [pinyinStrArray replaceObjectAtIndex:i withObject:[PinyinFormatter formatHanyuPinyinWithNSString: 36 | [pinyinStrArray objectAtIndex:i]withHanyuPinyinOutputFormat:outputFormat]]; 37 | } 38 | return pinyinStrArray; 39 | } 40 | else return nil; 41 | } 42 | 43 | + (NSArray *)getUnformattedHanyuPinyinStringArrayWithChar:(unichar)ch { 44 | return [[ChineseToPinyinResource getInstance] getHanyuPinyinStringArrayWithChar:ch]; 45 | } 46 | 47 | + (NSArray *)toTongyongPinyinStringArrayWithChar:(unichar)ch { 48 | return [PinyinHelper convertToTargetPinyinStringArrayWithChar:ch withPinyinRomanizationType: TONGYONG_PINYIN]; 49 | } 50 | 51 | + (NSArray *)toWadeGilesPinyinStringArrayWithChar:(unichar)ch { 52 | return [PinyinHelper convertToTargetPinyinStringArrayWithChar:ch withPinyinRomanizationType: WADEGILES_PINYIN]; 53 | } 54 | 55 | + (NSArray *)toMPS2PinyinStringArrayWithChar:(unichar)ch { 56 | return [PinyinHelper convertToTargetPinyinStringArrayWithChar:ch withPinyinRomanizationType: MPS2_PINYIN]; 57 | } 58 | 59 | + (NSArray *)toYalePinyinStringArrayWithChar:(unichar)ch { 60 | return [PinyinHelper convertToTargetPinyinStringArrayWithChar:ch withPinyinRomanizationType: YALE_PINYIN]; 61 | } 62 | 63 | + (NSArray *)convertToTargetPinyinStringArrayWithChar:(unichar)ch 64 | withPinyinRomanizationType:(NSString *)targetPinyinSystem { 65 | NSArray *hanyuPinyinStringArray = [PinyinHelper getUnformattedHanyuPinyinStringArrayWithChar:ch]; 66 | if (nil != hanyuPinyinStringArray) { 67 | NSMutableArray *targetPinyinStringArray = [NSMutableArray arrayWithCapacity:hanyuPinyinStringArray.count]; 68 | for (int i = 0; i < (int) [hanyuPinyinStringArray count]; i++) { 69 | 70 | } 71 | return targetPinyinStringArray; 72 | } 73 | else return nil; 74 | } 75 | 76 | + (NSArray *)toGwoyeuRomatzyhStringArrayWithChar:(unichar)ch { 77 | return [PinyinHelper convertToGwoyeuRomatzyhStringArrayWithChar:ch]; 78 | } 79 | 80 | + (NSArray *)convertToGwoyeuRomatzyhStringArrayWithChar:(unichar)ch { 81 | NSArray *hanyuPinyinStringArray = [PinyinHelper getUnformattedHanyuPinyinStringArrayWithChar:ch]; 82 | if (nil != hanyuPinyinStringArray) { 83 | NSMutableArray *targetPinyinStringArray =[NSMutableArray arrayWithCapacity:hanyuPinyinStringArray.count]; 84 | for (int i = 0; i < (int) [hanyuPinyinStringArray count]; i++) { 85 | } 86 | return targetPinyinStringArray; 87 | } 88 | else return nil; 89 | } 90 | 91 | + (NSString *)toHanyuPinyinStringWithNSString:(NSString *)str 92 | withHanyuPinyinOutputFormat:(HanyuPinyinOutputFormat *)outputFormat 93 | withNSString:(NSString *)seperater { 94 | NSMutableString *resultPinyinStrBuf = [[NSMutableString alloc] init]; 95 | for (int i = 0; i < str.length; i++) { 96 | NSString *mainPinyinStrOfChar = [PinyinHelper getFirstHanyuPinyinStringWithChar:[str characterAtIndex:i] withHanyuPinyinOutputFormat:outputFormat]; 97 | if (nil != mainPinyinStrOfChar) { 98 | [resultPinyinStrBuf appendString:mainPinyinStrOfChar]; 99 | if (i != [str length] - 1) { 100 | [resultPinyinStrBuf appendString:seperater]; 101 | } 102 | } 103 | else { 104 | [resultPinyinStrBuf appendFormat:@"%C",[str characterAtIndex:i]]; 105 | } 106 | } 107 | return resultPinyinStrBuf; 108 | } 109 | 110 | + (NSString *)getFirstHanyuPinyinStringWithChar:(unichar)ch 111 | withHanyuPinyinOutputFormat:(HanyuPinyinOutputFormat *)outputFormat { 112 | NSArray *pinyinStrArray = [PinyinHelper getFormattedHanyuPinyinStringArrayWithChar:ch withHanyuPinyinOutputFormat:outputFormat]; 113 | if ((nil != pinyinStrArray) && ((int) [pinyinStrArray count] > 0)) { 114 | return [pinyinStrArray objectAtIndex:0]; 115 | } 116 | else { 117 | return nil; 118 | } 119 | } 120 | 121 | - (id)init { 122 | return [super init]; 123 | } 124 | 125 | @end 126 | -------------------------------------------------------------------------------- /ZYPinYinSearch/ZYPinYinSearchLib/ZYPinYinSearch.h: -------------------------------------------------------------------------------- 1 | // 2 | // ZYPinYinSearch.h 3 | // ZYPinYinSearch 4 | // 5 | // Created by soufun on 15/7/27. 6 | // Copyright (c) 2015年 ZY. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "ZYSearchModel.h" 11 | @interface ZYPinYinSearch : NSObject 12 | 13 | 14 | 15 | /** 16 | * 搜索数组,返回新的数组。目前支持NSString,NSDictionnary,自定义Model,后面两个可以指定按照哪个字段搜索 17 | * 18 | * @param originalArray 要搜索的数据源 19 | * @param searchText 搜索的文本 20 | * @param propertyName 按照字典中或者model中哪个字段搜索,如果数组中存的是NSString,则传@""即可 21 | * @example _dataSourceArray = [ZYPinYinSearch searchWithOriginalArray:_originalArray andSearchText:searchBar.text andSearchByPropertyName:@"name"]; 22 | */ 23 | +(NSArray *)searchWithOriginalArray:(NSArray *)originalArray andSearchText:(NSString *)searchText andSearchByPropertyName:(NSString *)propertyName NS_DEPRECATED_IOS(2_0, 2_0, "Use +searchByPropertyName: withOriginalArray: searchText: success: failure:, instead"); 24 | 25 | /** 26 | * 异步搜索,在数据量大的时候不阻塞主线程,在success里回调搜索结果,failure里回调错误信息 27 | */ 28 | +(void)searchByPropertyName:(NSString *)propertyName withOriginalArray:(NSArray *)originalArray searchText:(NSString *)searchText success:(void(^)(NSArray *results))success failure:(void(^)(NSString *errorMessage))failure; 29 | 30 | /** 设置多音字情况下特定词语的拼音 */ 31 | +(void)setupReplacement:(ZYReplacement)relacement; 32 | /** 清除自定义设置 */ 33 | +(void)removeReplacement; 34 | @end 35 | -------------------------------------------------------------------------------- /ZYPinYinSearch/ZYPinYinSearchLib/ZYPinYinSearch.m: -------------------------------------------------------------------------------- 1 | // 2 | // ZYPinYinSearch.m 3 | // ZYPinYinSearch 4 | // 5 | // Created by soufun on 15/7/27. 6 | // Copyright (c) 2015年 ZY. All rights reserved. 7 | // 8 | 9 | #import "ZYPinYinSearch.h" 10 | #import "ChineseInclude.h" 11 | #import "PinYinForObjc.h" 12 | #import "objc/runtime.h" 13 | 14 | @implementation ZYPinYinSearch 15 | +(void)setupReplacement:(ZYReplacement)relacement{ 16 | [ZYSearchModel setupReplacement:relacement]; 17 | } 18 | +(void)removeReplacement{ 19 | [ZYSearchModel removeReplacement]; 20 | } 21 | +(NSArray *)searchWithOriginalArray:(NSArray *)originalArray andSearchText:(NSString *)searchText andSearchByPropertyName:(NSString *)propertyName{ 22 | ZYSearchModel * searchModel = [ZYSearchModel new]; 23 | searchModel.originalArray = originalArray; 24 | searchModel.searchText = searchText; 25 | searchModel.propertyName = propertyName; 26 | 27 | //如果数据合法,返回"string" 或者 "model" 或者 "dict",不合法则返回错误信息 28 | NSString * type = [searchModel chekIsLegal]; 29 | if (![@[@"string",@"model",@"dict"]containsObject:type]) { 30 | NSLog(@"%@",type); 31 | return originalArray; 32 | } 33 | return [searchModel search]; 34 | } 35 | 36 | +(void)searchByPropertyName:(NSString *)propertyName withOriginalArray:(NSArray *)originalArray searchText:(NSString *)searchText success:(void (^)(NSArray *))success failure:(void (^)(NSString *))failure{ 37 | ZYSearchModel * searchModel = [ZYSearchModel new]; 38 | searchModel.originalArray = originalArray; 39 | searchModel.searchText = searchText; 40 | searchModel.propertyName = propertyName; 41 | //如果数据合法,返回"string" 或者 "model" 或者 "dict",不合法则返回错误信息 42 | NSString * type = [searchModel chekIsLegal]; 43 | if (![@[@"string",@"model",@"dict"]containsObject:type]) { 44 | NSLog(@"%@",type); 45 | if (failure) { 46 | failure(type); 47 | } 48 | return; 49 | } 50 | __block NSArray * results ; 51 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 52 | results = [searchModel search]; 53 | dispatch_async(dispatch_get_main_queue(), ^{ 54 | if (success) { 55 | success(results); 56 | } 57 | }); 58 | }); 59 | } 60 | @end 61 | -------------------------------------------------------------------------------- /ZYPinYinSearch/ZYPinYinSearchLib/ZYSearchModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // ZYSearchModel.h 3 | // ZYPinYinSearch 4 | // 5 | // Created by soufun on 17/6/13. 6 | // Copyright © 2017年 ZY. All rights reserved. 7 | // 8 | 9 | #import 10 | /** 自定义把汉语词组转化成拼音,处理多音字的情况 */ 11 | typedef NSDictionary * (^ZYReplacement)(); 12 | @interface ZYSearchModel : NSObject 13 | @property (nonatomic,copy)NSArray * originalArray; 14 | @property (nonatomic,copy)NSString * searchText; 15 | @property (nonatomic,copy)NSString * propertyName; 16 | @property (nonatomic,copy)NSString * type; 17 | -(NSString *)chekIsLegal; 18 | -(NSArray *)search; 19 | 20 | /** 设置多音字情况下特定词语的拼音 */ 21 | +(void)setupReplacement:(ZYReplacement)relacement; 22 | +(void)removeReplacement; 23 | @end 24 | -------------------------------------------------------------------------------- /ZYPinYinSearch/ZYPinYinSearchLib/ZYSearchModel.m: -------------------------------------------------------------------------------- 1 | 2 | 3 | // 4 | // ZYSearchModel.m 5 | // ZYPinYinSearch 6 | // 7 | // Created by soufun on 17/6/13. 8 | // Copyright © 2017年 ZY. All rights reserved. 9 | // 10 | 11 | #import "ZYSearchModel.h" 12 | #import "objc/runtime.h" 13 | #import "ChineseInclude.h" 14 | #import "PinYinForObjc.h" 15 | static const char ZYReplacementKey = '\0'; 16 | static const char ZYCachedProperties = '\0'; 17 | @implementation ZYSearchModel 18 | -(NSString *)chekIsLegal{ 19 | NSString * type; 20 | if(self.originalArray.count <= 0){ 21 | return @"数据源不能为空"; 22 | } 23 | else{ 24 | id object = self.originalArray[0]; 25 | if ([object isKindOfClass:[NSString class]]) { 26 | type = @"string"; 27 | } 28 | else if([object isKindOfClass:[NSDictionary class]]){ 29 | type = @"dict"; 30 | NSDictionary * dict = self.originalArray[0]; 31 | BOOL isExit = NO; 32 | for (NSString * key in dict.allKeys) { 33 | if([key isEqualToString:self.propertyName]){ 34 | isExit = YES; 35 | break; 36 | } 37 | } 38 | if (!isExit) { 39 | return [NSString stringWithFormat:@"数据源中的字典没有你指定的key:%@",self.propertyName]; 40 | } 41 | } 42 | else{ 43 | type = @"model"; 44 | NSMutableArray *cachedProperties = objc_getAssociatedObject([object class], &ZYCachedProperties); 45 | if (!cachedProperties) { 46 | cachedProperties = [NSMutableArray array]; 47 | Class c = [object class]; 48 | while (c && c != [NSObject class]) { 49 | unsigned int outCount, i; 50 | objc_property_t *properties = class_copyPropertyList(c, &outCount); 51 | for (i = 0; i0&&![ChineseInclude isIncludeChineseInString:self.searchText]) { 75 | for (int i=0; i0) { 95 | [dataSourceArray addObject:self.originalArray[i]]; 96 | continue; 97 | } 98 | NSString *tempPinYinHeadStr = [PinYinForObjc chineseConvertToPinYinHead:tempString]; 99 | NSRange titleHeadResult=[tempPinYinHeadStr rangeOfString:self.searchText options:NSCaseInsensitiveSearch]; 100 | if (titleHeadResult.length>0) { 101 | [dataSourceArray addObject:self.originalArray[i]]; 102 | continue; 103 | } 104 | } 105 | else { 106 | NSRange titleResult=[tempString rangeOfString:self.searchText options:NSCaseInsensitiveSearch]; 107 | if (titleResult.length>0) { 108 | [dataSourceArray addObject:self.originalArray[i]]; 109 | continue; 110 | } 111 | } 112 | } 113 | } else if (_searchText.length>0&&[ChineseInclude isIncludeChineseInString:self.searchText]) { 114 | for (id object in self.originalArray) { 115 | NSString * tempString; 116 | if ([self.type isEqualToString:@"string"]) { 117 | tempString = object; 118 | } 119 | else{ 120 | tempString = [object valueForKey:self.propertyName]; 121 | } 122 | NSRange titleResult=[tempString rangeOfString:self.searchText options:NSCaseInsensitiveSearch]; 123 | if (titleResult.length>0) { 124 | [dataSourceArray addObject:object]; 125 | } 126 | } 127 | } 128 | return [dataSourceArray copy]; 129 | } 130 | 131 | +(void)setupReplacement:(ZYReplacement)relacement{ 132 | if (relacement && [relacement() isKindOfClass:[NSDictionary class]]) { 133 | objc_setAssociatedObject(self, &ZYReplacementKey, relacement(), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 134 | } else { 135 | objc_setAssociatedObject(self, &ZYReplacementKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 136 | } 137 | } 138 | +(void)removeReplacement{ 139 | objc_setAssociatedObject(self, &ZYReplacementKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 140 | } 141 | @end 142 | -------------------------------------------------------------------------------- /ZYPinYinSearch/ZYSearchViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ZYSearchViewController.h 3 | // ZYPinYinSearch 4 | // 5 | // Created by soufun on 15/7/27. 6 | // Copyright (c) 2015年 ZY. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ZYSearchViewController : UIViewController 12 | @property(nonatomic,copy)NSString * type; 13 | @end 14 | -------------------------------------------------------------------------------- /ZYPinYinSearch/ZYSearchViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ZYSearchViewController.m 3 | // ZYPinYinSearch 4 | // 5 | // Created by soufun on 15/7/27. 6 | // Copyright (c) 2015年 ZY. All rights reserved. 7 | // 8 | 9 | #import "ZYSearchViewController.h" 10 | #import "Person.h" 11 | #import "ZYPinYinSearch.h" 12 | @interface ZYSearchViewController () 13 | @property (nonatomic,strong) NSMutableArray * originalArray; 14 | @property (nonatomic,strong) NSArray * dataSourceArray; 15 | @property (nonatomic,strong) UITableView * tableView; 16 | @property (nonatomic,strong) UIBarButtonItem * searchButton; 17 | @property (nonatomic,strong) UISearchBar * searchBar; 18 | @property (nonatomic,strong) UIBarButtonItem * backButton; 19 | @end 20 | 21 | @implementation ZYSearchViewController 22 | 23 | - (void)viewDidLoad { 24 | [super viewDidLoad]; 25 | [self initData];//根据上个页面传过来的type值,初始化模拟数据 26 | [self createUI]; 27 | } 28 | #pragma -mark 自定义方法 29 | -(void)initData{ 30 | _originalArray = [NSMutableArray array]; 31 | NSArray * personNames = @[@"长春",@"重庆",@"李四",@"王五",@"赵六",@"孙七"]; 32 | NSArray * nicknames = @[@"帅哥",@"王大妞",@"李傻子",@"王瘸子",@"赵瞎子",@"孙子"]; 33 | if([self.type isEqualToString:@"字符串"]){ 34 | for (int i = 0; i < personNames.count; i++) { 35 | [_originalArray addObject:personNames[i]];//原始数据,数组中保存字符串 36 | } 37 | } 38 | else if([self.type isEqualToString:@"字典"]){ 39 | for (int i = 0; i < personNames.count; i++) { 40 | NSDictionary * dic = [NSDictionary dictionaryWithObjects:@[personNames[i],[NSString stringWithFormat:@"%d",i+24]] forKeys:@[@"name",@"age"]]; 41 | [_originalArray addObject:dic];//原始数据,数组中保存字典 42 | } 43 | } 44 | else if([self.type isEqualToString:@"Model"]){ 45 | for (int i = 0; i < personNames.count; i++) { 46 | Person * person = [Person CreatePersonWithName:personNames[i] andNickname:nicknames[i]]; 47 | [_originalArray addObject:person];//原始数据,数组中保存Model对象 48 | } 49 | } 50 | 51 | _dataSourceArray = [NSArray arrayWithArray:_originalArray]; 52 | } 53 | -(void)createUI{ 54 | self.title = self.type; 55 | self.view.backgroundColor = [UIColor colorWithRed:26/255.0 green:61/255.0 blue:89/255.0 alpha:1]; 56 | [self.navigationController.navigationBar.backItem setHidesBackButton:YES]; 57 | UIView * tempView = [[UIView alloc]initWithFrame:CGRectZero]; 58 | [self.view addSubview:tempView]; 59 | self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, kWidth, kHight - 64) style:UITableViewStylePlain]; 60 | self.tableView.delegate = self; 61 | self.tableView.dataSource = self; 62 | self.tableView.backgroundColor = [UIColor clearColor]; 63 | [self.view addSubview:self.tableView]; 64 | 65 | UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 66 | searchBtn.frame = CGRectMake(0, 0, 28, 22); 67 | [searchBtn setBackgroundImage:[UIImage imageNamed:@"searchButton"] forState:UIControlStateNormal]; 68 | [searchBtn addTarget:self action:@selector(jumpToSearch) forControlEvents:UIControlEventTouchUpInside]; 69 | _searchButton= [[UIBarButtonItem alloc] initWithCustomView:searchBtn]; 70 | self.navigationItem.rightBarButtonItem = _searchButton; 71 | 72 | UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 73 | backBtn.frame = CGRectMake(0, 0, 28, 22); 74 | [backBtn setBackgroundImage:[UIImage imageNamed:@"backArrow"] forState:UIControlStateNormal]; 75 | [backBtn addTarget:self action:@selector(backward) forControlEvents:UIControlEventTouchUpInside]; 76 | _backButton = [[UIBarButtonItem alloc] initWithCustomView:backBtn]; 77 | self.navigationItem.leftBarButtonItem = _backButton; 78 | 79 | 80 | } 81 | - (void)jumpToSearch 82 | { 83 | self.navigationItem.rightBarButtonItem=nil; 84 | _searchBar = [[UISearchBar alloc] init]; 85 | _searchBar.center = CGPointMake(kWidth/2, 84); 86 | _searchBar.frame = CGRectMake(10, 20,kWidth-20, 0); 87 | [_searchBar setContentMode:UIViewContentModeBottomLeft]; 88 | _searchBar.delegate = self; 89 | _searchBar.backgroundColor=[UIColor clearColor]; 90 | _searchBar.searchBarStyle=UISearchBarStyleDefault; 91 | _searchBar.showsCancelButton =YES; 92 | _searchBar.tag=1000; 93 | [self.navigationController.navigationBar addSubview:_searchBar]; 94 | _searchBar.placeholder = @"关键字搜索"; 95 | //------------------------------------------------------------------- 96 | [_searchBar becomeFirstResponder]; 97 | } 98 | - (void)backward 99 | { 100 | [self.navigationController popToRootViewControllerAnimated:YES]; 101 | } 102 | #pragma -mark tableViewDataSource 103 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; 104 | { 105 | return _dataSourceArray.count; 106 | } 107 | 108 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 109 | UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 110 | if (!cell) { 111 | cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"]; 112 | } 113 | cell.backgroundColor = [UIColor clearColor]; 114 | cell.textLabel.textColor = [UIColor whiteColor]; 115 | cell.detailTextLabel.textColor = [UIColor whiteColor]; 116 | if([self.type isEqualToString:@"字符串"]){ 117 | cell.textLabel.text = _dataSourceArray[indexPath.row]; 118 | } 119 | else if([self.type isEqualToString:@"字典"]){ 120 | NSDictionary * dict = _dataSourceArray[indexPath.row]; 121 | cell.textLabel.text = dict[@"name"]; 122 | cell.detailTextLabel.text = [NSString stringWithFormat:@"年龄:%@",dict[@"age"]]; 123 | } 124 | else if([self.type isEqualToString:@"Model"]){ 125 | Person * person = _dataSourceArray[indexPath.row]; 126 | cell.textLabel.text = person.name; 127 | cell.detailTextLabel.text = [NSString stringWithFormat:@"外号:%@",person.nickname]; 128 | } 129 | return cell; 130 | } 131 | 132 | #pragma -mark searchBarDelegate 133 | -(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar 134 | { 135 | self.navigationItem.rightBarButtonItem = _searchButton; 136 | [_searchBar resignFirstResponder]; 137 | [_searchBar removeFromSuperview]; 138 | } 139 | -(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar 140 | { 141 | if ([searchBar.text isEqualToString:@""]) { 142 | _dataSourceArray = _originalArray; 143 | 144 | } 145 | else{ 146 | #warning 主要功能,调用方法实现搜索 147 | [ZYPinYinSearch searchByPropertyName:@"name" withOriginalArray:_originalArray searchText:searchBar.text success:^(NSArray *results) { 148 | _dataSourceArray = results; 149 | [_tableView reloadData]; 150 | } failure:^(NSString *errorMessage) { 151 | 152 | }]; 153 | } 154 | 155 | self.navigationItem.rightBarButtonItem = _searchButton; 156 | [_searchBar resignFirstResponder]; 157 | [_searchBar removeFromSuperview]; 158 | } 159 | -(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{ 160 | if ([searchText isEqualToString:@""]) { 161 | _dataSourceArray = _originalArray; 162 | [_tableView reloadData]; 163 | } 164 | else{ 165 | #warning 主要功能,调用方法实现搜索 166 | [ZYPinYinSearch searchByPropertyName:@"name" withOriginalArray:_originalArray searchText:searchBar.text success:^(NSArray *results) { 167 | _dataSourceArray = results; 168 | [_tableView reloadData]; 169 | } failure:^(NSString *errorMessage) { 170 | 171 | }]; 172 | } 173 | 174 | } 175 | -(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar 176 | { 177 | //取消按钮 重置 178 | UITextField *tf; 179 | for (UIView *view in [[_searchBar.subviews objectAtIndex:0] subviews]) { 180 | if ([view isKindOfClass:[UITextField class]]) { 181 | tf=(UITextField *)view; 182 | } 183 | } 184 | [_searchBar setShowsCancelButton:YES animated:YES]; 185 | _searchBar.showsCancelButton=YES; 186 | for(UIView *subView in searchBar.subviews){ 187 | if([subView isKindOfClass:UIButton.class]){ 188 | [(UIButton*)subView setTitle:@"取消" forState:UIControlStateNormal]; 189 | UIButton *button=(UIButton*)subView; 190 | button.titleLabel.textColor=[UIColor whiteColor]; 191 | } 192 | } 193 | //取消字体变白 194 | UIButton *cancelButton; 195 | UIView *topView = _searchBar.subviews[0]; 196 | for (UIView *subView in topView.subviews) { 197 | if ([subView isKindOfClass:NSClassFromString(@"UINavigationButton")]) { 198 | cancelButton = (UIButton*)subView; 199 | } 200 | } 201 | if (cancelButton) { 202 | NSLog(@"%@",NSStringFromCGRect(cancelButton.frame)); 203 | //Set the new title of the cancel button 204 | [cancelButton setTitle:@" " forState:UIControlStateNormal]; 205 | [cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 206 | cancelButton.titleLabel.textColor=[UIColor whiteColor]; 207 | cancelButton.titleLabel.font = [UIFont fontWithName:@"Heiti SC" size:20]; 208 | [cancelButton removeFromSuperview]; 209 | UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(-5, -5,40,40)]; 210 | lable.textAlignment=NSTextAlignmentLeft; 211 | lable.text=@"取消"; 212 | lable.textColor=[UIColor whiteColor]; 213 | [cancelButton addSubview:lable]; 214 | lable.font = [UIFont fontWithName:@"Heiti SC" size:16]; 215 | [cancelButton addSubview:lable]; 216 | 217 | } 218 | UIButton * button; 219 | [button setTintColor: nil]; 220 | 221 | } 222 | 223 | - (void)didReceiveMemoryWarning { 224 | [super didReceiveMemoryWarning]; 225 | // Dispose of any resources that can be recreated. 226 | } 227 | 228 | /* 229 | #pragma mark - Navigation 230 | 231 | // In a storyboard-based application, you will often want to do a little preparation before navigation 232 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 233 | // Get the new view controller using [segue destinationViewController]. 234 | // Pass the selected object to the new view controller. 235 | } 236 | */ 237 | 238 | @end 239 | -------------------------------------------------------------------------------- /ZYPinYinSearch/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // ZYPinYinSearch 4 | // 5 | // Created by soufun on 15/7/27. 6 | // Copyright (c) 2015年 ZY. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | --------------------------------------------------------------------------------