YYLabel和YYTextView的使用

本文介绍如何在iOS应用中实现可点击的文字标签效果,并提供YYLabel和YYTextView的具体使用案例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

       在开发中,一般都会有遵守服务条款之类的声明,而在这些提示语当中,常常会设置某一段文字可以点击,值得注意的是控制类型必须改成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);
    }];
复制代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值