0

im parsing HTML string - has both text and image - to NSMutableAttributedString to display in UITextView using the following code. All tags are perfectly parsed except; if the image is large, it is not resized to fit in the frame. It gets truncated. Any help?

do {

        let attributes =  try
            NSMutableAttributedString(
                data: conversationForum.discussionText.dataUsingEncoding(NSUTF8StringEncoding)!,
                options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,  NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding],
                documentAttributes: nil)

        let range = NSMakeRange(0, attributes.string.characters.count)
        attributes.addAttributes([NSFontAttributeName: font], range: range)

        self.attributedText = attributes
    }

    catch {
        self.attributedText = NSMutableAttributedString()
    }

for example: the actual image is http://www.cruxcatalyst.com/wp-content/uploads/lalalala.jpg but i'm getting it truncated as "this"

  • Why are you not using a UIWebView instead? – fishinear Jul 16 '16 at 16:04
  • Possible duplicate of [NSAttributedString: Fit image to container](https://stackoverflow.com/questions/28920795/nsattributedstring-fit-image-to-container) – Larme Jun 27 '17 at 20:36

0 Answers0