iOS-NSString汉子转拼音

//
//  ViewController.m
//  QQQQQ
//
//  Created by ZFJ_APPLE on 16/1/8.
//  Copyright © 2016年岁月轻狂. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [superviewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self uiConfig];
}

- (void)uiConfig
{
    NSString *str = @"岁月轻狂_杰";
    NSMutableString *mutableStr = [str mutableCopy];
    //CFRange range = CFRangeMake(0, str.length);
    //NULL  默认全部转换
    //汉子转拼音有音标
    BOOL ret =CFStringTransform((__bridgeCFMutableStringRef)mutableStr, NULL,kCFStringTransformMandarinLatin, NO);
    if(ret)
    {
        NSLog(@"%@",mutableStr);
    }
    //汉子转拼音无音标
    BOOL ret1 =CFStringTransform((__bridgeCFMutableStringRef)mutableStr, NULL,kCFStringTransformStripDiacritics, NO);
    if(ret1)
    {
        NSLog(@"%@",mutableStr);
    }

}

- (void)didReceiveMemoryWarning {
    [superdidReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end


2016-01-08 14:21:21.837 QQQQQ[4357:211360] suì yuè qīng kuáng_jié

2016-01-08 14:21:21.847 QQQQQ[4357:211360] sui yue qing kuang_jie








你可能感兴趣的:(iOS开发)