如何在UITextView中插入超链接?

发布于 2024-12-08 19:10:51 字数 290 浏览 2 评论 0原文

我想插入一个超链接,就像我们在 uiwebview 中一样。由于链接显示为“阅读更多”,当用户单击它时,它必须重定向到 iPhone 浏览器(即 safari)中的 URL。

请不要建议我使用 UIwebview 来代替它。并且不要建议我

textView.dataDetectorTypes = UIDataDetectorTypeLink;

因为在第二种方式中,网址显示给用户,这是我不想要的。

给我任何其他建议来实现此目的或任何示例代码。

I want to insert a hyperlink as we have in uiwebview. As the link displayed as Read More and when user click on it then it must be redirected to a URL in iPhone browser (i.e safari).

Please don't suggest me using UIwebview in place of it. And don't suggest me

textView.dataDetectorTypes = UIDataDetectorTypeLink;

Because in second way the url displayed to the user, which I don't want.

Give me any other suggestions to achieve this or any sample code for it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执妄 2024-12-15 19:10:51

它必须是一个textView吗?我做了一些类似的添加一个带有文本、背景不可见的按钮,并添加了单击时调用 safari 的操作,如下所示:

    UIButton *hiperlinkButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [hiperlinkButton setTitle:@"your text" forState:UIControlStateNormal];
    [hiperlinkButton setTitleColor:[UIColor colorWithRed:204.0/255.0 green:33.0/255.0 blue:0.0/255.0 alpha:1.0] forState:UIControlStateNormal];
    [hiperlinkButton setFrame:CGRectMake(yourposition and size)];
    [hiperlinkButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [hiperlinkButton addTarget:self action:@selector(callSafari:) forControlEvents:UIControlEventTouchUpInside];
    [contactsView insertSubview:hyperlinkButton aboveSubview:contactsView];

Is it have to be a textView? I did some similar adding a button with the text, background invisible and add the action to call safari on click, like this:

    UIButton *hiperlinkButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [hiperlinkButton setTitle:@"your text" forState:UIControlStateNormal];
    [hiperlinkButton setTitleColor:[UIColor colorWithRed:204.0/255.0 green:33.0/255.0 blue:0.0/255.0 alpha:1.0] forState:UIControlStateNormal];
    [hiperlinkButton setFrame:CGRectMake(yourposition and size)];
    [hiperlinkButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [hiperlinkButton addTarget:self action:@selector(callSafari:) forControlEvents:UIControlEventTouchUpInside];
    [contactsView insertSubview:hyperlinkButton aboveSubview:contactsView];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文