A
A
Abra Kadabra2017-05-30 18:13:54
iOS
Abra Kadabra, 2017-05-30 18:13:54

How to position text in textView to the right using NSMutableAttributedString?

How to position text in textView to the right?
I am using NSMutableAttributedString.
Attributes I set like this:

let attrs = [
        NSForegroundColorAttributeName : UIColor.init(hexString: "#FF9500"),
        NSTextAlignment: NSTextAlignment.right
    ] as [String : Any]

Assigning attributes to a string:
viewString.append(
  NSMutableAttributedString(
     string: symbol,
     attributes: attrs1
   )
)

Perhaps the property for the location is set incorrectly? The color changes successfully.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Gorb, 2017-06-07
@Jmaster

let string = "Any String"
let style = NSMutableParagraphStyle()
style.alignment = .right
        
let attributes = [
     NSForegroundColorAttributeName: UIColor.white,
     NSParagraphStyleAttributeName: style
   ]
        
let attributedString = NSMutableAttributedString(string: string, attributes: attributes)
textView.attributedText = attributedString

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question