-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
yylabel中全部是emoji表情时,设置行间距无效 #309
Comments
在拼接好最终字符串后,再设置 yy_lineSpacing。 |
初始化view (void)initContentView { YYLabel *sendMessage = [YYLabel new]; sendMessage.numberOfLines = 0; sendMessage.lineBreakMode = NSLineBreakByCharWrapping; // sendMessage.textVerticalAlignment = YYTextVerticalAlignmentCenter; // sendMessage.textColor = [UIColor whiteColor]; // sendMessage.font = [UIFont systemFontOfSize:16]; // sendMessage.backgroundColor = [UIColor redColor]; [self.contentView addSubview:sendMessage]; self.sendMessage = sendMessage; } (void)setChatContentValue:(NSDictionary *)dict NSMutableAttributedString *nick_attr = [[NSMutableAttributedString alloc] initWithString:dict[@"nick"]]; NSMutableAttributedString *message_attr = [[NSMutableAttributedString alloc] initWithString:dict[@"message"]]; YYTextShadow *shadow = [YYTextShadow new]; attr.yy_lineSpacing = 0; |
我猜,你是在添加了 Emoji 后,发现每行的高度变大了,然后希望调整 lineSpacing 来去掉行距? 如果你的问题是这样,那是因为 emoji 本身 font 自带的 ascent 和 descent 比一般字体要大,会把文本行撑高,这不是 line spacing 所能控制的。你可以试着给 label 添加一个 linePositionModifier,或者给 attr 设置一个 maximumLineHeight 属性。 如果不是这样,那我就看不出代码的问题了,提供一下截图和 Demo 来说明问题吧。 |
初始化view
{
YYLabel *sendMessage = [YYLabel new];
sendMessage.numberOfLines = 0;
sendMessage.lineBreakMode = NSLineBreakByCharWrapping;
// sendMessage.textVerticalAlignment = YYTextVerticalAlignmentCenter;
// sendMessage.textColor = [UIColor whiteColor];
// sendMessage.font = [UIFont systemFontOfSize:16];
// sendMessage.backgroundColor = [UIColor redColor];
[self.contentView addSubview:sendMessage];
self.sendMessage = sendMessage;
}
内容赋值
(void)setChatContentValue:(NSDictionary *)dict
{
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] init];
attr.yy_lineSpacing = 0;
NSMutableAttributedString *nick_attr = [[NSMutableAttributedString alloc] initWithString:dict[@"nick"]];
nick_attr.yy_color = [CommonFuction colorFromHexRGB:@"ffd944"];
nick_attr.yy_font = [UIFont boldSystemFontOfSize:16];
[attr appendAttributedString:nick_attr];
NSMutableAttributedString *message_attr = [[NSMutableAttributedString alloc] initWithString:dict[@"message"]];
message_attr.yy_color = [UIColor whiteColor];
message_attr.yy_font = [UIFont boldSystemFontOfSize:16];
[attr appendAttributedString:message_attr];
YYTextShadow *shadow = [YYTextShadow new];
shadow.color = [UIColor colorWithWhite:0.000 alpha:0.5];
shadow.offset = CGSizeMake(0, 0);
shadow.radius = 1;
attr.yy_textShadow = shadow;
self.sendMessage.attributedText = attr;
}
The text was updated successfully, but these errors were encountered: