Open hangzhoujc opened 7 years ago
无论直接设NSBaselineOffsetAttributeName,还是通过设yy_baselineOffset,在iOS10以前的系统上都不行,只有在iOS10上可行。
NSMutableAttributedString str1 = [[NSMutableAttributedString alloc] initWithString:@"精华" attributes:@{NSBaselineOffsetAttributeName:@5, NSFontAttributeName:[UIFont systemFontOfSize:11], NSForegroundColorAttributeName:[UIColor redColor]}]; str1.yy_baselineOffset = @5; NSMutableAttributedString str2 = [[NSMutableAttributedString alloc] initWithString:@"从业20年的高端客户经营秘籍" attributes:nil]; str2.yy_color = [UIColor blackColor]; str2.yy_font = [UIFont systemFontOfSize:17]; [str1 appendAttributedString:str2]; YYLabel *l = [[YYLabel alloc] init]; l.frame = CGRectMake(15, 300, self.view.frame.size.width - 30, 46); l.numberOfLines = 0; l.lineBreakMode = NSLineBreakByCharWrapping; l.textVerticalAlignment = YYTextVerticalAlignmentCenter; l.attributedText = str1; [self.view addSubview:l];
请问这个问题解决了吗
恩,如有问题留下qq
无论直接设NSBaselineOffsetAttributeName,还是通过设yy_baselineOffset,在iOS10以前的系统上都不行,只有在iOS10上可行。
NSMutableAttributedString str1 = [[NSMutableAttributedString alloc] initWithString:@"精华" attributes:@{NSBaselineOffsetAttributeName:@5, NSFontAttributeName:[UIFont systemFontOfSize:11], NSForegroundColorAttributeName:[UIColor redColor]}]; str1.yy_baselineOffset = @5; NSMutableAttributedString str2 = [[NSMutableAttributedString alloc] initWithString:@"从业20年的高端客户经营秘籍" attributes:nil]; str2.yy_color = [UIColor blackColor]; str2.yy_font = [UIFont systemFontOfSize:17]; [str1 appendAttributedString:str2]; YYLabel *l = [[YYLabel alloc] init]; l.frame = CGRectMake(15, 300, self.view.frame.size.width - 30, 46); l.numberOfLines = 0; l.lineBreakMode = NSLineBreakByCharWrapping; l.textVerticalAlignment = YYTextVerticalAlignmentCenter; l.attributedText = str1; [self.view addSubview:l];