【问题标题】:How do I indent part of the text in a UITextView如何缩进 UITextView 中的部分文本
【发布时间】:2017-07-20 02:06:01
【问题描述】:

我想在 UITextView 中缩进部分文本

原文:

Paragraph Here:
Hello World this is just a test. 
Hello World this is just a test.
Hello World this is just a test

如何让它显示为这样

Paragraph Here:
    Hello World this is just a test. 
    Hello World this is just a test.
    Hello World this is just a test

我不想在开头使用空格,因为如果设备真的很小,它会搞砸的

【问题讨论】:

标签: swift string text swift3 uitextview


【解决方案1】:
var textMessage = "Paragraph Here:\nHello World this is just a test.\nHello World this is just a test.\nHello World this is just a test"
    textMessage = textMessage.replacingOccurrences(of: "\n", with: "\n\t")
    textView.text = textMessage

试试上面的代码。 希望对你有帮助。

【讨论】:

  • 文本将有 20 个句子长,我希望所有这些都被标记。我不能在某个地方这样做,因为它会根据人们使用的设备而有所不同。
  • 那么你必须对 UITextView 使用填充。
【解决方案2】:

对于其他关注此问题的人,我在此博客上找到了解决方案:

https://bendodson.com/weblog/2018/08/09/bulleted-lists-with-uilabel/

“大部分繁重的工作由 NSParagraphStyle 完成 名为 headIndent 的属性,它添加了固定数量的填充到 除了段落的第一行之外的所有内容”

【讨论】:

    【解决方案3】:

    我使用“\t”来创建一个标签。

           let  string = "\tHello World this is just a test."
    

    【讨论】:

    • 文本将有 20 个句子长,我希望所有这些都被标记。我不能在某个地方这样做,因为它会根据人们使用的设备而有所不同。
    【解决方案4】:

    如果您希望每一行都在新行中,请使用新行。示例代码

    let textMessage = "Hello World this is just a test.\nHello World this is just a test.\nHello World this is just a test"
    self.textView.text = textMessage
    

    或者如果你想在 UITextView 的开头留一点空间,那么就使用它

     textView.layer.sublayerTransform = CATransform3DMakeTranslation(10, 0, 0)
    

    【讨论】:

    • 文本将有 20 个句子长,我希望所有这些都被标记。我不能在某个地方这样做,因为它会因人使用的设备而异。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多