gpt4 book ai didi

ios - 如何在 ios 中的特定 textView 文本上创建超链接

转载 作者:行者123 更新时间:2023-11-28 21:10:03 29 4
gpt4 key购买 nike

NSString *str = @"We’ll notify you before we make changes to these 
terms and give you the opportunity to review and comment on the revised
terms before continuing to use. If you have any question just email
me.";
NSMutableAttributedString *aStr = [[NSMutableAttributedString
alloc]initWithString:str attributes:nil];
[str rangeOfString:@"email"]];
[self.textView setAttributedText:aStr];

这是我要在电子邮件上创建链接的文本。

最佳答案

你可以这样做,

NSString *str = @"We’ll notify you before we make changes to these terms and give you the opportunity to review and comment on the revised terms before continuing to use. If you have any question just email me.";
NSMutableAttributedString *aStr = [[NSMutableAttributedString alloc]initWithString:str attributes:nil];
[aStr addAttribute:NSLinkAttributeName value:@"Your Link here" range:[str rangeOfString:@"email"]];
[self.textView setAttributedText:aStr];

更新

您可以添加字体属性使其变为粗体。例如,如果您想将 We'll notify 设为粗体

  [aStr addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:14.0] range:[str rangeOfString:@"We’ll notify"]];

在将属性文本设置到 textView 之前添加此行!

关于ios - 如何在 ios 中的特定 textView 文本上创建超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43907582/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com