0

I have a scroll view with a text label pinned to it. The text label contains html attributed text (converted by using the accepted answer here) which includes images such as graphs. I'm able to get the text to fit on screen, but the images are being cut off on the trailing side

Edit: The image is being pulled in like so:

<p><img src="https://lh5.googleusercontent.com/ZhaF0f-JiPOmvvFS4qor‌ -gVpqFALuXcbwM8bBHIB‌ 0I9dFRoUZkxQUx5G-0Cb‌ PcuRNnC2Zw0Ty3lp9Ykr‌ 3X00Iy0RfiLVJnsLP9Fu‌ C_wORRhixVd3fm5JA27I‌ MUTkFPf1JkZvLBFW" style="border:none; height:324px; width:624px" /></p>

Edit: The Scroll View's width is fixed because I'm only wanting it to scroll vertically

Edit: Constraints are set in storyboard if that mattersenter image description here

froggomad
  • 1,747
  • 2
  • 17
  • 40
  • try adding `label.setNeedsLayout()` and `label.layoutIfNeeded()` after setting the value – Malik Jun 26 '17 at 05:57
  • Also, try removing the

    tags from the html and see if that works

    – Malik Jun 26 '17 at 05:58
  • it happening because image being displayed here takes it original size you just need to give a defined size to image so it don't cross the view on trailing or leading side. Set a frame that have parameter of width as self.view.frame.size.width – iOS Geek Jun 26 '17 at 06:34
  • Thanks both of you. @Malik - I tried setNeedsLayout and layoutIfNeeded after setting the value and the image still bleeds off @ iOS Geek - Do you mean setting the label's frame to the view's width? Like `label.frame.size.width = self.view.frame.size.width`? If so, this had no effect – froggomad Jun 26 '17 at 06:58
  • @froggomad Have you tried removing the

    tags from the html?

    – Malik Jun 26 '17 at 07:00
  • trying to, not used to working with Attributed strings – froggomad Jun 26 '17 at 07:19
  • removed

    tags - no difference

    – froggomad Jun 26 '17 at 15:25

1 Answers1

1

The problem you have is the image takes its original size.

You should set the max width of the image in the html, like so :

<img style="max-width: 100%;" src="mysrc.jpg" />
Damien
  • 3,322
  • 3
  • 19
  • 29
  • Thanks but I'm pulling this from an API I don't control – froggomad Jun 26 '17 at 15:12
  • Parse the data you retrieve then, add the attribute style to every . – Damien Jun 27 '17 at 10:27
  • Thanks for that. `let politImage = self.Request.article.replacingOccurrences(of: " – froggomad Jun 27 '17 at 14:19
  • lol I just realized I'm printing the wrong thing - the tag is changed but the result is the same. I'm about 18 years past having done any serious html work though so I'm not sure `` produces what you're after – froggomad Jun 27 '17 at 14:24
  • oops - I reformatted that to ` – froggomad Jun 27 '17 at 14:32
  • I've got that to `` - but no change – froggomad Jun 27 '17 at 14:51
  • I just realized I'm also using a different result from yesterday since the top story changed and the image is being pulled in a different way from the example in my question. Sorry for any confusion there – froggomad Jun 27 '17 at 14:56
  • 6 months later I realized I fubared as usual lol "\"max-width: \(self.view.frame.width)px\"" was what I needed there, your answer of max-width being the key – froggomad Dec 19 '17 at 16:04