#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");
}