YYLabel bug
NSMutableAttributedString *text = [NSMutableAttributedString new];
UIFont *font = [UIFont boldSystemFontOfSize:16];
for (int i = 0; i < tags.count; i++) {
NSString *tag = tags[i];
UIColor *tagStrokeColor = UIColorHex(818e91);
NSMutableAttributedString *tagText = [[NSMutableAttributedString alloc] initWithString:tag];
[tagText yy_insertString:@" " atIndex:0];
[tagText yy_appendString:@" "];
tagText.yy_font = font;
tagText.yy_color = tagStrokeColor;
YYTextBorder *border = [YYTextBorder new];
border.strokeWidth = 1.2f;
border.strokeColor = tagStrokeColor;
border.fillColor = [UIColor clearColor];
border.cornerRadius = 100; // a huge value
border.lineJoin = kCGLineJoinBevel;
border.insets = UIEdgeInsetsMake(1.5, -6, 0, -6);
[tagText yy_setTextBackgroundBorder:border range:[tagText.string rangeOfString:tag]];
[text appendAttributedString:tagText];
}
text.yy_lineSpacing = 0;
text.yy_lineBreakMode = NSLineBreakByCharWrapping;
我的YYLabel 是写在cell上得并且自动布局强制大小的,当我的内容加起来刚好1行以内,就不会报错,而内容大于1行时,YYLabel库里面就直接crash了。
请提供下错误日志或者 crash 处的断点截图,方便定位错误位置
目前我测试暂时没有发现错误:
NSArray *tags = @[@"haha", @"hehe", @"你好",@"haha", @"hehe", @"你好",@"haha", @"hehe", @"你好",@"haha", @"hehe", @"你好",@"haha", @"hehe", @"你好",];
text = [NSMutableAttributedString new];
UIFont *font = [UIFont boldSystemFontOfSize:16];
for (int i = 0; i < tags.count; i++) {
NSString *tag = tags[i];
UIColor *tagStrokeColor = UIColorHex(818e91);
NSMutableAttributedString *tagText = [[NSMutableAttributedString alloc] initWithString:tag];
[tagText yy_insertString:@" " atIndex:0];
[tagText yy_appendString:@" "];
tagText.yy_font = font;
tagText.yy_color = tagStrokeColor;
YYTextBorder *border = [YYTextBorder new];
border.strokeWidth = 1.2f;
border.strokeColor = tagStrokeColor;
border.fillColor = [UIColor clearColor];
border.cornerRadius = 100; // a huge value
border.lineJoin = kCGLineJoinBevel;
border.insets = UIEdgeInsetsMake(1.5, -6, 0, -6);
[tagText yy_setTextBackgroundBorder:border range:[tagText.string rangeOfString:tag]];
[text appendAttributedString:tagText];
}
text.yy_lineSpacing = 0;
text.yy_lineBreakMode = NSLineBreakByCharWrapping;
YYLabel *label = [YYLabel new];
label.frame = CGRectMake(10, 100, 200, 200);
label.numberOfLines = 0;
label.textContainerInset = UIEdgeInsetsMake(10, 10, 10, 10);
label.attributedText = text;
[self.view addSubview:label];
还是需要你贴一下错误日志,我这里定位不到错误。。
yylabel支持自动布局吗?性能怎么样
发自我的 iPhone
在 2015年11月24日,18:14,yimiaodaren [email protected] 写道:
NSMutableAttributedString *text = [NSMutableAttributedString new]; UIFont *font = [UIFont boldSystemFontOfSize:16]; for (int i = 0; i < tags.count; i++) { NSString *tag = tags[i]; UIColor *tagStrokeColor = UIColorHex(818e91); NSMutableAttributedString *tagText = [[NSMutableAttributedString alloc] initWithString:tag]; [tagText yy_insertString:@" " atIndex:0]; [tagText yy_appendString:@" "]; tagText.yy_font = font; tagText.yy_color = tagStrokeColor;
YYTextBorder *border = [YYTextBorder new]; border.strokeWidth = 1.2f; border.strokeColor = tagStrokeColor; border.fillColor = [UIColor clearColor]; border.cornerRadius = 100; // a huge value border.lineJoin = kCGLineJoinBevel; border.insets = UIEdgeInsetsMake(1.5, -6, 0, -6); [tagText yy_setTextBackgroundBorder:border range:[tagText.string rangeOfString:tag]]; [text appendAttributedString:tagText];} text.yy_lineSpacing = 0; text.yy_lineBreakMode = NSLineBreakByCharWrapping; 我的YYLabel 是写在cell上得并且自动布局强制大小的,当我的内容加起来刚好1行以内,就不会报错,而内容大于1行时,YYLabel库里面就直接crash了。
— Reply to this email directly or view it on GitHub.
关于 AutoLayout,见这个讨论:#1。
YYLabel 通常来说性能比 UILabel 差一些,但如果文本内容比较复杂时,性能就相差不多了。 另外 YYLabel 可以开启异步排版和绘制,这样主线程资源占用就比 UILabel 要好很多了。
2015-11-30 11:01:14.750 YYTextDemo[4153:40881] * Terminating app due to uncaught exception 'NSRangeException', reason: '* -[**NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array' * First throw call stack: ( 0 CoreFoundation 0x000000010ba56f35 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010da02bb7 objc_exception_throw + 45 2 CoreFoundation 0x000000010b941f33 -[__NSArrayM objectAtIndex:] + 227 3 YYTextDemo 0x000000010b1b4be9 YYTextDrawBorder + 3737 4 YYTextDemo 0x000000010b1b2a11 -[YYTextLayout drawInContext:size:point:view:layer:debug:cancel:] + 449 5 YYTextDemo 0x000000010b19b531 __30-[YYLabel newAsyncDisplayTask]_block_invoke304 + 897 6 YYTextDemo 0x000000010b20fd83 -[YYTextAsyncLayer _displayAsync:] + 2451 7 YYTextDemo 0x000000010b20f3e8 -[YYTextAsyncLayer display] + 152 8 QuartzCore 0x000000010d1f8801 _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 301 9 QuartzCore 0x000000010d1f8889 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 35 10 QuartzCore 0x000000010d16663e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242 11 QuartzCore 0x000000010d16774a _ZN2CA11Transaction6commitEv + 390 12 UIKit 0x000000010be4054d -[UIApplication _reportMainSceneUpdateFinished:] + 44 13 UIKit 0x000000010be41238 -[UIApplication _runWithMainScene:transitionContext:completion:] + 2642 14 UIKit 0x000000010be3fbf2 -[UIApplication workspaceDidEndTransaction:] + 179 15 FrontBoardServices 0x000000010ff672a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16 16 CoreFoundation 0x000000010b98c53c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK + 12 17 CoreFoundation 0x000000010b982285 __CFRunLoopDoBlocks + 341 18 CoreFoundation 0x000000010b982045 __CFRunLoopRun + 2389 19 CoreFoundation 0x000000010b981486 CFRunLoopRunSpecific + 470 20 UIKit 0x000000010be3f669 -[UIApplication _run] + 413 21 UIKit 0x000000010be42420 UIApplicationMain + 1282 22 YYTextDemo 0x000000010b22490f main + 111 23 libdyld.dylib 0x000000010e3ee145 start + 1 24 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
代码断点是YYTextLayout.m 2666行 CGRect curRect= ((NSValue *)runRects[0]).CGRectValue;
Thread 1Queue : com.apple.main-thread (serial) 0 0x00000001099b9b8a in objc_exception_throw () 1 0x00000001078f8f33 in -__NSArrayM objectAtIndex: 2 0x000000010716bbe9 in YYTextDrawBorder at /Users/admin/Downloads/YYText-master/YYText/Component/YYTextLayout.m:2666 3 0x0000000107169a11 in -[YYTextLayout drawInContext:size:point:view:layer:debug:cancel:] at /Users/admin/Downloads/YYText-master/YYText/Component/YYTextLayout.m:3211 4 0x0000000107152531 in 30-[YYLabel newAsyncDisplayTask]block_invoke304 at /Users/admin/Downloads/YYText-master/YYText/YYLabel.m:937 5 0x00000001071c6d83 in -[YYTextAsyncLayer displayAsync:] at /Users/admin/Downloads/YYText-master/YYText/Utility/YYTextAsyncLayer.m:195 6 0x00000001071c63e8 in -[YYTextAsyncLayer display] at /Users/admin/Downloads/YYText-master/YYText/Utility/YYTextAsyncLayer.m:124 7 0x00000001091af801 in CA::Layer::display_if_needed(CA::Transaction) () 8 0x00000001091af889 in CA::Layer::layout_and_display_if_needed(CA::Transaction) () 9 0x000000010911d63e in CA::Context::commit_transaction(CA::Transaction) () 10 0x000000010911e74a in CA::Transaction::commit() () 11 0x0000000107df754d in -UIApplication _reportMainSceneUpdateFinished: 12 0x0000000107df8238 in -UIApplication _runWithMainScene:transitionContext:completion: 13 0x0000000107df6bf2 in -UIApplication workspaceDidEndTransaction: 14 0x000000010bf1e2a3 in __31-[FBSSerialQueue performAsync:]_block_invoke () 15 0x000000010794353c in __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK* () 16 0x0000000107939285 in __CFRunLoopDoBlocks () 17 0x0000000107939045 in __CFRunLoopRun () 18 0x0000000107938486 in CFRunLoopRunSpecific () 19 0x0000000107df6669 in -UIApplication _run 20 0x0000000107df9420 in UIApplicationMain () 21 0x00000001071db90f in main at /Users/admin/Downloads/YYText-master/Demo/YYTextDemo/main.m:14
感谢提供log,我修复一下
Fixed,请稍后更新代码测试一下看看是否修复。
请问一下,当numberOfLines = 1的时候。我添加了很多个tag。放不下的直接不显示出来,不需要点点点 或者只显示半个。。lineBreakMode = NSLineBreakByClipping 能不能整个圈圈一起不显示呢?