技术的乐趣在于分享,欢迎多多交流,多多沟通。
全部博文(877)
分类: 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");
}