IOS_11_PINYIN4OBJC Kanji to Pinyin demo

Source: Internet
Author: User

Eventually:





ViewController.h

  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


Viewcontroller.m

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, has the following features: 1. High efficiency, using data cache, after the first initialization, Ruby data into the file cache and memory cache,  The efficiency of the rear conversion is greatly improved; 2. Support custom formatting, pinyin case and so on; 3. Pinyin data integrity, support Chinese Simplified and traditional, and the network of popular related projects, data is very full, almost no conversion error problems. 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: Compared to previous projects such as Pinyin,poapinyin and Pymethod, PINYIN4OBJC's speed is very fast for tone formatting. For example: "Liu" after the formatting of the word "liu2" or "Liu" or "Liú" to the Special pinyin u display format. For example, "U:" or "V" or "ü" case 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, for example: LIU2 hanyupinyintonetype.without_tone  silent tones, for example: Liu hanyupinyintonetype.with_tone_mark  is represented by a tone symbol, for example: Liú set special Pinyinü Display format: Outputformat.setvchartype (Hanyupinyinvchartype);  The parameter 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  represents the character in V, for example: LV hanyupinyinvchartype.with_u_unicode  to ü */#import " ViewController.h "#import" PinYin4Objc.h "@interface Viewcontroller () @end @implementation viewcontroller//Click the button,    Convert Kanji to Pinyin-(Ibaction) Btnokclick: (ID) sender{//1, get input text nsstring *inputtext=_textfieldinput.text;        Robust judgment 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 parameters of the phonetic formatting object------Focus */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 conversion start time Nstimeinterval starttime=[[nsdate Date] timeIntervalSince1970]; 5, Pinyin tool class method to convert Chinese characters to pinyin, parameter 1: input kanji, Parameter 2: Formatter, parameter 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 the custom method and exit the keyboard [self exitkeyboard]; }//custom method, exit keyboard-(void) exitkeyboard{//exit keyboard//mode 1:self.view all text boxes inside (including descendant controls ...)    All exit the first responder [Self.view Endediting:yes];        Return Mode 2://Traverse all the controls inside the UIView, Resignfirstresponder for (UIView *obj in self.view.subviews) {if ([obj ISKINDOFC        Lass:[uitextfield class]]) {[obj resignfirstresponder]; }}///Mode 3://At the beginning of the Self.view, a full screen transparent button, the connection, as long as the screen in the blank area of the click, you can call the above Way 1, exit the keyboard} @end








Storyboard






Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.