title: How to add VoiceOver support to image created from a view and then saved / shared in share sheet in iOS?
body: <p>I have an app with UIView showing quoted text. A save button creates an image of the view using UIGraphicsBeginImageContextWithOptions. This image is then shared using the Share Sheet or saved into the user's camera roll.</p>
  <p>I want to be able to provide VoiceOver support to read the text on the image / or the text that I give should be read.</p>
  <p>Since the generated image is not a part of the shown view, I used <a href="https://developer.apple.com/documentation/uikit/uiaccessibilityelement/1619582-initwithaccessibilitycontainer?language=objc" rel="nofollow noreferrer">initWithAccessibilityContainer</a>. Used instructions on <a href="https://medium.com/short-swift-stories/the-voice-of-ios-e1e5ea535592" rel="nofollow noreferrer">this</a> post and <a href="https://stackoverflow.com/questions/15071984/how-do-you-set-the-accessibility-label-on-an-image-that-is-drawn-with-core-graph">this</a>.</p>
  <p>This is the code that gets called on button click :</p>
  <pre><code>    @IBAction func onButtonClick(_ sender: UIButton) {
      
      guard let resizedImage = generateImage(from: view) else {
          fatalError(&quot;No image created&quot;)
      }
      
      let imageRect = CGRect(x: 0, y: 0, width: resizedImage.size.width, height: resizedImage.size.height)
      resizedImage.isAccessibilityElement = true
      resizedImage.accessibilityLabel = &quot;Image created&quot;
      resizedImage.accessibilityTraits = .image
     
      let groupedElement = UIAccessibilityElement(accessibilityContainer: self.view)
      groupedElement.accessibilityLabel = &quot;This is the description that i want to be read to voiceOver enabled users&quot;
      groupedElement.accessibilityFrameInContainerSpace = imageRect
      groupedElement.accessibilityFrame = self.view.convert(imageRect, to: nil)
      
      var elements = [UIAccessibilityElement]()
      elements.append(groupedElement)
      
      accessibilityElements = [elements]
      
      UIImageWriteToSavedPhotosAlbum(resizedImage, self, #selector(onImageSaved(_:didFinishSavingWithError:contextInfo:)), nil)
      
  }`
  </code></pre>
  <p>But when I save the image and go to my camera roll and check the label through Accessibility Inspector I get the &quot;Photo, Landscape, 3:28PM&quot; only being read for the image. I expect this &quot;This is the description that I want to be read to voiceOver enabled users&quot;.</p>
  <p>I read on <a href="https://www.apple.com/in/accessibility/iphone/vision/" rel="nofollow noreferrer">Apple's site</a> that VoiceOver can &quot;It can also read aloud text in an image — whether it’s a snapshot of a receipt or a magazine article — even if it hasn’t been annotated.&quot;</p>
  <p>Could someone please let me know if the technique I am following is the right one? And what changes need to be done to get the required text on VoiceOver?</p>