Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2604349
  • 博文数量: 877
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 5920
  • 用 户 组: 普通用户
  • 注册时间: 2013-12-05 12:25
个人简介

技术的乐趣在于分享,欢迎多多交流,多多沟通。

文章分类

全部博文(877)

文章存档

2021年(2)

2016年(20)

2015年(471)

2014年(358)

2013年(26)

分类: iOS平台

2015-11-02 10:55:29

#define THEROWLENGTH    16

#define UnicodeSTART    9728 - 1


+ (NSString *)replaceUnicode:(NSString *)unicodeStr {

    

    NSString *tempStr1 = [unicodeStr stringByReplacingOccurrencesOfString:@"\\u" withString:@"\\U"];

    NSString *tempStr2 = [tempStr1 stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];

    NSString *tempStr3 = [[@"\"" stringByAppendingString:tempStr2] stringByAppendingString:@"\""];

    NSData *tempData = [tempStr3 dataUsingEncoding:NSUTF8StringEncoding];

    NSString* returnStr = [NSPropertyListSerialization propertyListFromData:tempData

                                                           mutabilityOption:NSPropertyListImmutable

                                                                     format:NULL

                                                           errorDescription:NULL];

    

    //NSLog(@"Output = %@", returnStr);

    

    return [returnStr stringByReplacingOccurrencesOfString:@"\\r\\n" withString:@"\n"];

}

- (void)showUnicodeIcon

{

    j = THEROWLENGTH;

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        NSTimer *timerRun = [NSTimer timerWithTimeInterval:3 target:self selector:@selector(timeShow) userInfo:nil repeats:YES];

        [[NSRunLoop currentRunLoop] addTimer:timerRun forMode:NSRunLoopCommonModes];

        [[NSRunLoop currentRunLoop] run];

//        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:20.0]]; //主线程等待,但让出主线程时间片,然后过10秒后返回

    });

}

- (void)timeShow

{

    NSMutableString  *stirn2= [NSMutableString stringWithCapacity:0 ];

    

        for (int i = 1; i <= j; i++) {

            //i = 1 UnicodeSTART处进行调整

            [stirn2 appendFormat:@"\\u%x", UnicodeSTART + i % THEROWLENGTH + (THEROWLENGTH * (i / THEROWLENGTH)) ] ;

            

//            NSLog(@"the string is #### %@", stirn2);

            

            NSString *unicodeStringShow = [[self class] replaceUnicode:stirn2];

            

            if (i % THEROWLENGTH == 0) {

                NSLog(@"the unicode is %@", unicodeStringShow);

                        //回到主线程

                        dispatch_async(dispatch_get_main_queue(), ^{

                            //refresh UI

                            _label.font = [UIFont fontWithName:@"Helvetica" size:40.f];

                            _label.textAlignment = NSTextAlignmentLeft;

                            _label.numberOfLines = 0;//行数设置为1,不设置时系统会默认行数为1

//                            [_label sizeToFit];

                            _label.text = [NSString stringWithString:unicodeStringShow];

                            

                        });

            }

//            NSLog(@"the unicode is %@", unicodeString);

            

            if (i % THEROWLENGTH == 0 && (i != 0)) {

                //清空本String

                [stirn2 setString:@""];

//                NSLog(@"the string is ===%@", stirn2);

            }

            

        }

        j += 16;

    

    NSLog(@"%@", @"timeShow");

}

阅读(1056) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~