gpt4 book ai didi

Xcode 创建可点击的文本

转载 作者:行者123 更新时间:2023-12-01 01:14:25 26 4
gpt4 key购买 nike

我正在尝试创建一个可以在其中包含可点击文本的对象。

例如:我向用户显示了文本:
“请在接受注册之前核实条款和条件。”

我只想将“条款和条件”文本显示为链接。文本将带有蓝色下划线。

当用户单击文本时,我希望它们被导航到我的条款和条件 View Controller 页面。所以链接是应用程序内部的,而不是外部网页。

问题

  • 如何仅显示可链接特定文本的文本?
  • 如何通过用户单击链接文本“序列”到 ViewController 页面?
  • 最佳答案

    你可以用 TTTAttributedLabel 来做到这一点.从自述文件:

    In addition to supporting rich text, TTTAttributedLabel allows you to automatically detect links for URLs, addresses, phone numbers, and dates, or allow you to embed your own.

    label.dataDetectorTypes = UIDataDetectorTypeAll; // Automatically detect links when the label text is subsequently changed
    label.delegate = self; // Delegate methods are called when the user taps on a link (see `TTTAttributedLabelDelegate` protocol)

    label.text = @"Fork me on GitHub! (http://github.com/mattt/TTTAttributedLabel/)"; // Repository URL will be automatically detected and linked

    NSRange range = [label.text rangeOfString:@"me"];
    [label addLinkToURL:[NSURL URLWithString:@"http://github.com/mattt/"] withRange:range]; // Embedding a custom link in a substring

    关于Xcode 创建可点击的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12916569/

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