sali
sali

Reputation: 179

how to make UITextView text alignemnt right and Justified at the same time

I need my long text inside UITextView to be aligned right and Justified at the same time . But I notice that I could just select right or justified .How can I have both Alignments for my UItextView at the same time ?

Upvotes: 3

Views: 1535

Answers (4)

Mohammad Sadegh Panadgoo
Mohammad Sadegh Panadgoo

Reputation: 3989

You can do it like this (Swift 3,4):

var yourString = String()
let yourTextView = UITextView()

let attrText = NSMutableAttributedString(string: yourString)
            let paragraph = NSMutableParagraphStyle()
            paragraph.baseWritingDirection = .rightToLeft
            paragraph.alignment = .justified
            attrText.addAttribute(NSParagraphStyleAttributeName, value: paragraph, range: NSMakeRange(0, yourString.length))
yourTextView.attributedText = attrText

Upvotes: 5

Fahri Azimov
Fahri Azimov

Reputation: 11770

Hack it!(kidding:)). Set text alignment to the justified, set width that is less than screen width, move the text view to the right edge of the screen. Voila, it's right aligned and justified. Good luck!

Upvotes: 0

Pankaj Teckchandani
Pankaj Teckchandani

Reputation: 745

The best option available for your requirement at the moment is this enter image description here

Upvotes: 1

satheesh
satheesh

Reputation: 2834

You cannot achieve both alignment at the same time, But you can add a right alignment when entering the text in the textview, after you finished editing the textview set the text alignment to justify,

So Whenever you start editing the textview use right alignment and once you have finished editing set justify , simple :)

Upvotes: 0

Related Questions