Sunday, January 7, 2018

Setting an attributed string to an UITextView

Setting an attributed string to an UITextView can be pretty straight forward. See code sample below,

yourTextView.attributedText = Your attributed string

However, I noticed that the scroll position of the UITextView changes upon executing the above line of code. The solution is to disable scrolling before setting the text. The code below worked for me,

yourTextView.isScrollEnabled = false
yourTextView.attributedText = Your attributed string
yourTextView.isScrollEnabled = true

No comments: