Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 764
sali Avatar asked Nov 16 '25 05:11

sali


2 Answers

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
like image 163
Mohammad Sadegh Panadgoo Avatar answered Nov 18 '25 21:11

Mohammad Sadegh Panadgoo


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

like image 30
Pankaj Teckchandani Avatar answered Nov 18 '25 19:11

Pankaj Teckchandani