【问题标题】:Swift iOS TextView center and right align certain textSwift iOS TextView 居中并右对齐某些文本
【发布时间】:2019-07-23 15:07:22
【问题描述】:

我有一个 textview,我希望它类似于 iphone notes 应用程序。当用户单击居中对齐按钮时,我只希望该行上的任何内容居中对齐。我有这段代码,但是当我使用它时,它将整个 textview 文本设置为居中对齐,我只希望我所在的行居中对齐:

@IBAction func centerAlignmentBtn(_ sender: Any) {
     self.textView.textAlignment = .center
}

【问题讨论】:

标签: swift uitextview


【解决方案1】:

您可以设置对齐方式,然后设置文本书写方向。 喜欢就好。

self.textView.textAlignment = .justified //set text alignment center and justified
self.textView.makeTextWritingDirectionRightToLeft(true)//if you want set writing direction right to left
self.textView.makeTextWritingDirectionLeftToRight(true)//if you want set writing direction left to right

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-16
    • 2023-03-10
    • 1970-01-01
    • 2017-10-17
    • 2013-10-13
    相关资源
    最近更新 更多