Guest User

Untitled

a guest
Dec 12th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. if ([self.txtOutputTranslator baseWritingDirectionForPosition:[self.txtOutputTranslator beginningOfDocument] inDirection:UITextStorageDirectionForward] == UITextWritingDirectionLeftToRight)
  2. {
  3. self.txtOutputTranslator.textAlignment=NSTextAlignmentLeft;
  4. }
  5. else
  6. {
  7. self.txtOutputTranslator.textAlignment=NSTextAlignmentRight;
  8.  
  9. }
  10.  
  11. func textViewDidChange(_ textView: UITextView) {
  12. let baseWritingDirection = textView.baseWritingDirection(for: textView.beginningOfDocument, in: .forward)
  13. switch baseWritingDirection {
  14. case .leftToRight:
  15. textView.textAlignment = .left // for example
  16. case .rightToLeft:
  17. textView.textAlignment = .right // for example
  18. case .natural:
  19. // WARNING: use natural alignment carefully as it won't work with reusable table view cells. In common cases baseWritingDirection won't return this parameter
  20. textView.textAlignment = .natural
  21. }
  22. }
Add Comment
Please, Sign In to add comment