YYKit是個(gè)好東西-YYLabel實(shí)現(xiàn)一個(gè)文本多個(gè)點(diǎn)擊事件

有時(shí)候需要實(shí)現(xiàn)一個(gè)文本多個(gè)點(diǎn)擊事件的東西,如此圖中的用戶(hù)協(xié)議和隱私政策都需要點(diǎn)擊跳轉(zhuǎn)對(duì)應(yīng)的頁(yè)面,可以使用YYLabel來(lái)快速實(shí)現(xiàn)

NSString *agreementText = @"點(diǎn)擊登錄即表示已同意并同意《xxx用戶(hù)協(xié)議》與《xxx隱私政策》";

NSMutableAttributedString *text ?= [[NSMutableAttributedString alloc] initWithString:agreementText];

text.lineSpacing = 5;//行間距

text.font = [UIFont systemFontOfSize:14];

text.color = [UIColor grayColor];

[text setTextHighlightRange:NSMakeRange(13, 9) color:[UIColor redColor] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {

? ? ? ? ? ? NSLog(@"用戶(hù)協(xié)議被點(diǎn)擊了");

? }];

? ? ? ? [text setTextHighlightRange:NSMakeRange(agreementText.length-9, 9) color:[UIColor redColor]? backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {

? ? ? ? ? ?NSLog(@"隱私政策被點(diǎn)擊了");

? ? ? ? }];

YYLabel *agreementLabel = [YYLabel new];

agreementLabel.numberOfLines = 0;//多行

agreementLabel.preferredMaxLayoutWidth = kScreenWidth-85;//最大寬度

agreementLabel.attributedText = text;

[self.view addSubview:agreementLabel];

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容