skip to Main Content

I’m trying to remove the background view for my UITargetPreview. I made the background color clear, however, you can still see the frame of the background.

This is what it currently looks like:

I currently have a view that has the text container and the image inside of it and that’s what I use as the view for the UITargetedPreview.

Is there a way to only show the image and the text and not the background frame?

4

Answers


  1. Have you tried subclassing the UIView as a UIControl?
    I had a similar issue but in my case the view for UITargetedPreview was glitchy. However, changing the UIView to a UIControl fixed everything.

    Login or Signup to reply.
  2. try removing shadow of that background view.

    Login or Signup to reply.
  3. There is a tricky method to hide the shadow and to do that you should find a view with _UIPlatterSoftShadowView class name in the view hierarchy and then hide it.

    func viewByClassName(view: UIView, className: String) -> UIView? {
        let name = NSStringFromClass(type(of: view))
        if name == className {
            return view
        }
        else {
            for subview in view.subviews {
                if let view = viewByClassName(view: subview, className: className) {
                    return view
                }
            }
        }
        return nil
    }
    
    override func tableView(_ tableView: UITableView, willDisplayContextMenu configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionAnimating?) {
        DispatchQueue.main.async {
            if let window = UIApplication.shared.delegate?.window! {
                if let view = self.viewByClassName(view: window, className: "_UIPlatterSoftShadowView") {
                    view.isHidden = true
                }
            }
        }
    }
    

    NOTE: It’s not documented internal class and can be changed anytime further but it works now on both ios 13/14.

    Login or Signup to reply.
  4. You need to study UIBezierPath() to outline the specific area you want to enclose before you present the target view.

    After that, you shall assign the specific path to shadow path / visible path

    let params = UIPreviewParameters()
            params.backgroundColor = .clear
            if #available(iOS 14.0, *) {
                params.shadowPath = bubblePath
            } else {
                params.visiblePath = bubblePath
            }
    
        
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search