2017-07-20 18 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。 –

相關問題