YYLabel顯示多行除了需要設置numberOfLines = 0以外,還需要設置preferredMaxLayoutWidth最大的寬度值才可以生效多行效果
YYLabel中的NSMutableAttributedString可以設置多屬性
yy_lineSpacing 文字行間距
yy_font 文字的字體大小
yy_color 文字的顏色
...
通過設置yy_setTextHighlightRange方法可以實現富文本中的文字的點擊效果,文字顏色,文字背景顏色等
eg:
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString: @"接下來,請您咨詢閱讀《xxx協議》!點擊以下同意按鈕,即表示您已閱讀且完全知悉《xxx協議》約定事項並表示同意!同意后您將正式擁有xxxxxx身份。"];
text.yy_lineSpacing = 5;
text.yy_font = [UIFont systemFontOfSize:14];
text.yy_color = kSystemGrayColor;
__weak typeof(self) weakself = self;
[text yy_setTextHighlightRange:NSMakeRange(10, 7) color:[UIColor colorWithHexString:@"0x22b4e1"] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
NSLog(@"xxx協議被點擊了");
if (weakself.agProtocolAction) {
weakself.agProtocolAction();
}
}];
_agressLabel.numberOfLines = 0; //設置多行顯示
_agressLabel.preferredMaxLayoutWidth = kScreenWidth - 30; //設置最大的寬度
_agressLabel.attributedText = text; //設置富文本
