I had an issue with a UItextView that was inside a UICollectionView cell. Sometimes the text in the UITextView was invisible until the user selected the view. This did not happen often. Usually the UITextView behaved correctly. I was running Xcode 8.3.3 and the code was in Swift 3.1.

I found the reason for this random bug to be the textContainerInset definition. I had it like this:

textView.textContainerInset = UIEdgeInsetsMake(0, -4, 0, 0)

The reason for this negative inset value was to remove the little extra padding on the left side of the UITextView. I cleared the definition to be:

textView.textContainerInset = UIEdgeInsetsMake(0, 0, 0, 0)

The random bug was gone and the UITexField behaves correctly every time now.

Leave a Comment

Your email address will not be published.