Reputation: 437
I have a textview and I want it similar to the iphone notes app. When a user clicks on the center align button I only want whatever is on that line to be center aligned. I have this code but when I use it, it sets the entire textview text to be center aligned, I only want the line I am on to be center aligned:
@IBAction func centerAlignmentBtn(_ sender: Any) {
self.textView.textAlignment = .center
}
Upvotes: 1
Views: 2052
Reputation: 475
you can set alignment justified and then set text writing direction. like as it.
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
Upvotes: 1