在Swift

时间:2018-08-25 14:20:18

标签: swift xcode uilabel uitextview

在文本视图/标签上划分文本,以便在单击单个句子时以不同的方式打开文本。

等:根据句号。

“文本视图/标签”中的文本已通过sqlite移出。我使用sqlite绘制数据,然后将文本合并为段落。我希望在打印每个句子时都打印有关该声明的信息。该应用程序是在Swift 4,XCode 9环境中编写的。

等文章:Lorem ipsum dolor坐在amet处,献身成才。不可抗力的双性恋。 Maecenas vel risus s鼠,乌龟turpis quis,马蒂斯lorem。暂停考试。

单独点击所有文本:

  • Lorem ipsum dolor坐着,安全奉献。

  • 不可抗力的双性恋。

  • Maecenas vel risus molestie,ultrices turpis quis,mattis lorem。

  • 中止quis ultrices sem。

文本必须为段落格式。这是一篇文章。我的目的不是以单独的提示形式显示它。我的目的是将每个事件分别连接到每个事件。

我使用了FRHyperLabel,但无法正常工作... Scroolview中的FRHyperLabel。点击有效,但操作错误。例如;我单击的是第二句,但它的行为就像第一句。

for eleman in articleSentenceList{
    let handler = {
        (hyperLabel: FRHyperLabel?, substring: String?) -> Void in

        let controller = UIAlertController(title: substring, message: eleman.v1, preferredStyle: UIAlertControllerStyle.alert)
        controller.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil))
        self.present(controller, animated: true, completion: nil)
    }

    let denemeString:String = eleman.v2

    let substring = denemeString[denemeString.startIndex..<denemeString.index(denemeString.startIndex, offsetBy: denemeString.count)]

    translateList.append(String(substring))

    txtTitle.setLinksForSubstrings([translateList.last!], withLinkHandler: handler)

}

0 个答案:

没有答案