2017-07-20 88 views
1

我想在一个UITextView我如何缩进文本的一部分,在一个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 

我不想在开始使用空格,因为如果设备真的很小,它会把所有东西搞乱

+0

这应该有助于 [https://stackoverflow.com/questions/25367502/create-space-at-the-beginning-of-a-uitextfield/27066764#27066764](https://stackoverflow.com/questions/25367502 /创建空间在开始的uitextfield/27066764#27066764) – Tom

+0

@Tom我可以添加填充到textView的一部分,而不是整个东西 –

回答

0

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

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

文本将会像20个句子长我希望所有这些都是标签。我不能在某个地方做到这一点,因为根据用户使用的设备不同,它会有所不同。 –

1

如果你想让每一行在新行中使用新行。示例代码

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) 
+0

该文本将会像20个句子一样长,我希望所有这些都是标签。我不能在某个地方做到这一点,因为根据用户使用的设备不同,它会有所不同。 –

0
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 

试试上面的代码。 我希望它可以帮助你。

+0

文本将会像20个句子一样长,我希望所有这些文本都是标签。我不能在某个地方做到这一点,因为根据用户使用的设备不同,它会有所不同。 –

+0

然后你必须使用填充到UITextView。 –

相关问题