【问题标题】:How to create Hyperlink on particular textView text in ios如何在ios中的特定textView文本上创建超链接
【发布时间】:2018-05-11 18:22:40
【问题描述】:
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];

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

【问题讨论】:

标签: ios objective-c


【解决方案1】:

你可以做类似的事情,

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 之前添加此行!

【讨论】:

  • 如何在这个字符串@Lion上设置标题
  • 标题是什么意思?
  • 假设我想在这个字符串上加粗一些文本,那么我将如何做到这一点
【解决方案2】:

将此属性添加到您的文本视图

textview.dataDetectorTypes = UIDataDetectorTypeLink;

【讨论】:

    猜你喜欢
    • 2016-08-18
    • 2013-07-10
    • 2014-06-10
    • 2013-12-10
    • 1970-01-01
    • 2016-07-08
    • 1970-01-01
    • 2016-07-17
    • 1970-01-01
    相关资源
    最近更新 更多