1

In my app I have a UITableView of posts. In those UITableView cells there are UITextViews with parsed HTML to an NSAttributedString.

I resize the images before the tableview is populated in a model

let mutableText = NSMutableAttributedString(attributedString: text)
                mutableText.enumerateAttribute(NSAttributedStringKey.attachment, in: NSMakeRange(0, mutableText.length), options: .init(rawValue: 0), using: { (value, range, stop) in
                    if let attachement = value as? NSTextAttachment {
                        let image = attachement.image(forBounds: attachement.bounds, textContainer: NSTextContainer(), characterIndex: range.location)!
                        let screenSize: CGRect = UIScreen.main.bounds
                        if image.size.width > screenSize.width {
                            attachement.bounds = CGRect(x: 0, y: 0, width: image.size.width * ((screenSize.width-75)/image.size.width), height: image.size.height * ((screenSize.width-75)/image.size.width))

                        }

                    }
                })

However, when I scroll on the TableView the performance is horrible. When I reach an image it stops scrolling for half a second. Without images, scrolling is quite smooth.

EDIT: Here is what the tableview looks like enter image description here

Sid Mhatre
  • 3,272
  • 1
  • 19
  • 38
  • Possible duplicate of [Slow load time for custom UIView with UITextView property in Swift](https://stackoverflow.com/questions/34199956/slow-load-time-for-custom-uiview-with-uitextview-property-in-swift) – Chris Lopez Mar 27 '18 at 01:31

0 Answers0