<span id="Label3"></p><p><p><span style="font-size:24px"><span style="background-color:rgb(204,204,204)">At last:</span></span></p></p><p><p><br></p></p><p><p><br></p></p><p><p><br></p></p><p><p><br></p></p><p><p></p></p><p class="p1"><p class="p1"><span style="font-size:24px; color:#ff0000"><span style="background-color:rgb(204,255,255)">ViewController.h</span></span></p></p><pre name="code" class="objc"><pre name="code" class="objc"> viewcontroller.h// pinyin4objc Kanji Pinyin Demo demo//// Created by Beyond on 14-7-26.// Copyright (c) 2014 com.beyond. All rights reserved.//#import <UIKit/UIKit.h> @interface viewcontroller:uiviewcontroller//input Box @property ( Nonatomic,weak) Iboutlet Uitextfield *textfieldinput;//show time how much @property (nonatomic,weak) iboutlet UILabel *labelTime;/ /display the number of words @property (nonatomic,weak) iboutlet UILabel *labelwordscount;//results box @property (nonatomic,weak) iboutlet Uitextview *textfieldresult;//conversion button@property (nonatomic,weak) iboutlet UIButton *btnok;-(ibaction) btnOKClick: (id ) sender; @end</pre></pre><br><br><p><p></p></p><p class="p1"><p class="p1"><span style="font-size:24px; color:#ff0000"><span style="background-color:rgb(255,204,255)">Viewcontroller.m</span></span></p></p><pre name="code" class="objc">VIEWCONTROLLER.M//PINYIN4OBJC Kanji Pinyin Demo demo////Created by beyond on 14-7-26.//Copyright (c) 2014 com.beyond. All rights reserved./* PINYIN4OBJC is a popular kanji (support simplified and traditional) Pinyin OBJC library, with the following Features: 1. High efficiency, using Data caching. After the first initialization, the ruby data is stored in the file cache and in the memory Cache. The efficiency of the rear conversion is greatly improved; 2. Support your own definition of formatting. Pinyin uppercase and lowercase and so on; 3. Pinyin data integrity, support Simplified Chinese and traditional, and the network of popular related projects than, the data is very full, almost no conversion error PROBLEM. PINYIN4OBJC is a popular objective-c library supporting convertion between Chinese (both simplified and Tranditional) Chara Cters and most popular Pinyin systems, it's performance is very efficient, data cached at first Time. The output format of pinyin could be customized. Performance Comparison: with the previous pinyin. Poapinyin and Pymethod and other projects, PINYIN4OBJC speed is very fast tone format. For example: "liu" After the formatting of the word "liu2" or "liu" or "liú" to the special pinyin U display Format.<p><p></p></p><p>For example, "u:" or "v" or "ü" uppercase and lowercase conversions. For example: "liu2" or "LIU2" to set the tone format: Outputformat.settonetype (hanyupinyintonetype); The parameter hanyupinyintonetype has the following constant object: hanyupinyintonetype.with_tone_number uses numbers to denote tones, such as: liu2 hanyupinyintonetype.without_tone Silent tone, Such as: Liu hanyupinyintonetype.with_tone_mark with a tone notation. For example: liú Set special Pinyin u display format: outputformat.setvchartype (hanyupinyinvchartype); The Hanyupinyinvchartype has the following constant Object: hanyupinyinvchartype.with_u_and_colon represents the ruby with a U and a Colon. For example,:lu:hanyupinyinvchartype.with_v to V for this character, for example: lv hanyupinyinvchartype.with_u_unicode to u = * * #import " ViewController.h "#import" PinYin4Objc.h "@interface viewcontroller () @end @implementation Viewcontroller//click button, Convert Kanji to Pinyin-(ibaction) btnokclick: (id) sender{//1, Get input text NSString *inputtext=_textfieldinput.text; Robust inferred if ([inputtext isequal:@ ""]) {_labeltime.text= @ ""; _labelwordscount.text = @ ""; _textfieldresult.text = @ ""; Input box Live Focus [_textfieldinput becomefirstresponder]; Return }//2, instantiating phonetic formatting objects Hanyupinyinoutputformat *outputformat=[[hanyupinyinoutputformat alloc] init]; 3, set the number of references for the phonetic formatting object------key/* typedef enum {tonetypewithtonenumber, number 1234 means tone tonetypewithouttone, no tones Tonetypewithtonemark Mark Tone This does not use}tonetype; typedef enum {vchartypewithuandcolon, vchartypewithv, vchartypewithuunicode}vchartype; *///tone is no Tone//[outputformat settonetype:tonetypewithouttone]; The tones are numbers, followed by the sky <-----> hai3 Kuo4 tian1 kong1 [outputformat settonetype:tonetypewithtonenumber]; This can't be used to mark tones ...//[outputformat settonetype:tonetypewithtonemark]; V Expression method: [outputformat setvchartype:vchartypewithv]; V Presentation Method://[outputformat setvchartype:vchartypewithuunicode]; V Presentation Method://[outputformat setvchartype:vchartypewithuandcolon]; The result is uppercase or lowercase, generally lowercase [outputformat setcasetype:casetypelowercase]; 4, record the start time of the conversion nstimeinterval starttime=[[NSDate date] timeIntervalSince1970]; 5, Pinyin Tool class method to convert Chinese characters to pinyin, 1: input Chinese characters, 2: formatter, number of 3:seperator delimiter NSString *outputpinyin=[pinyinhelper Tohanyupinyinstringwithnsstring:inputtext Withhanyupinyinoutputformat:outputformat withNSString:@ ""]; 6, Record conversion end time Nstimeinterval endtime=[[nsdate date] timeIntervalSince1970]; 7, The calculation time Nstimeinterval totaltime=endtime-starttime; 8, echo Results to interface _labeltime.text=[nsstring stringwithformat:@ "total time:%fs", totaltime]; _labelwordscount.text=[nsstring stringwithformat:@ "number of characters:%i", inputtext.length]; _textfieldresult.text=outputpinyin; NSLog (@ "%@", outputpinyin); Convert to Seconds//NSLog (@ "seconds:%f", (endtime-starttime)/(float) clocks_per_sec); Call yourself to define the method and exit the keyboard [self exitkeyboard]; }//yourself define the method, exit the Keyboard-(void) exitkeyboard{//exit the Keyboard//mode 1:self.view inside all the text boxes (including descendants control ...) All exit the first responder [self.view endediting:yes]; Return Mode 2://traverse all the controls inside the UIView, Resignfirstresponder for (UIView *obj on Self.View.subviews) {if ([obj Iskindofclass:[uitextfield class]]) {[obj resignfirstresponder]; }}///mode 3://at The beginning of the self.view, a full-screen transparent button, wiring, just to click in the blank area of the screen, you can call the above mode 1, exit the keyboard} @end</p></pre><br><br><p><p><br></p></p><p><p><br></p></p><p><p><br></p></p><p><p><br></p></p><p><p><br></p></p><p><p><br></p></p><p><p><span style="font-size:24px"><span style="background-color:rgb(204,204,204)">Storyboard</span></span></p></p><p><p><br></p></p><p><p><br></p></p><p><p><br></p></p><p><p><br></p></p><p><p><br></p></p> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article Bo master original articles, blogs, without consent may not be reproduced.</p></p> <p><p>Ios_ Chinese characters to pinyin _PINYIN4OBJC</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service