Search code examples
iosuitextfieldcore-text

Make UITextField not to draw image attachment but keep its frame


UITextField have very bad performance on drawing image attachments while scrolling on iPhone 6+/6s+. I am working on some subviews solution to overlap attachments with UIImageViews. It works well, but I need UITextView to stop drawing this attachments but keep attachment frames on their places.

I know about NSTextContainer exclusionPaths property, but not sure it will works well for async image loading. Image sizes will be known after downloading.


Solution

  • Found working solution by nilling [NSTextAttachment image] and restoring bounds:

    CGRect bounds = attachment.bounds;
    attachment.image = nil;
    attachment.bounds = bounds;