YYLabel和YYTextView的使用

2,012 阅读1分钟

       在开发中,一般都会有遵守服务条款之类的声明,而在这些提示语当中,常常会设置某一段文字可以点击,值得注意的是控制类型必须改成YYLabel class。

  • 1.YYLabel
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"我已阅读并接受"];
text.yy_color = [UIColor lightGrayColor];
text.yy_font = [UIFont systemFontOfSize:10];
NSMutableAttributedString *clickText = [[NSMutableAttributedString alloc] initWithString:@"《e联盟商城网络服务协议》"];
clickText.yy_font = [UIFont systemFontOfSize:10];
clickText.yy_color = [UIColor redColor];
[clickText yy_setTextHighlightRange:clickText.yy_rangeOfAll color:[UIColor redColor] backgroundColor:[UIColor greenColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
    [self showAlertView:@"协议即将添加"];
}];
[text appendAttributedString:clickText];
self.severiceLabel.attributedText = text;
  • 2.YYTextView
    self.textTF = [YYTextView new];
    self.textTF.textColor = [UIColor darkTextColor];
    self.textTF.font = [UIFont systemFontOfSize:12];
    self.textTF.placeholderFont = [UIFont systemFontOfSize:12];
    self.textTF.placeholderTextColor = [UIColor darkGrayColor];
    self.textTF.placeholderText = @"留下您的购物体验和使用感受,帮助其他小伙伴~";
    [self.textView addSubview:self.textTF];
    [self.textTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.textView);
    }];