0

Please find the below code,This is the code I am using it, I tried forceRight to left to customise it, but this is not helping.

from iOS 15 we have some Contextual menu thing by iOS UIkit, let interaction = UIContextMenuInteraction(delegate: self)

`

import UIKit

@available(iOS 14.0, *)
class ViewController: UIViewController, UIContextMenuInteractionDelegate {
  
    
    @IBOutlet weak var imageView: UIImageView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let interaction = UIContextMenuInteraction(delegate: self)
        imageView.addInteraction(interaction)
        imageView.isUserInteractionEnabled = true
        imageView.layer.cornerRadius = 25
        
    }
    //    func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
    //        return UIContextMenuConfiguration(identifier: "unique-id" as NSCopying, previewProvider: {
    //            let customView = NewViewController()
    //            return customView
    //        }, actionProvider: {_ in
    //            return self.createContextMenu()
    //        })
    //    }
    func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
        imageView.layer.borderWidth = 4
        imageView.layer.cornerRadius = 25
        imageView.layer.borderColor = CGColor.init(red: 256, green: 256, blue: 256, alpha: 1)
        return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { _ -> UIMenu? in
            return self.createContextMenu()
        }
    }
    func contextMenuInteraction(_ interaction: UIContextMenuInteraction, willEndFor configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionAnimating?) {
        self.imageView.layer.borderWidth = 0
    }
    
    func createContextMenu() -> UIMenu {
        let shareAction = UIAction(title: "Share", image: UIImage(systemName: "square.and.arrow.up")) { _ in
            self.imageView.layer.borderWidth = 0
            print("Share")
        }
        
        let copy = UIAction(title: "Copy", image: UIImage(systemName: "doc.on.doc")) { _ in
            print("Copy")
            self.imageView.layer.borderWidth = 0
        }
        
        let saveToPhotos = UIAction(title: "Add To Photos", image: UIImage(systemName: "photo")) { _ in
            print("Save to Photos")
            self.imageView.layer.borderWidth = 0
        }
        UIView.appearance().semanticContentAttribute = .forceRightToLeft
        return UIMenu(title: "", children: [saveToPhotos,copy,shareAction])
    }
}

`

current-UI< and > I want Something like this with contextual menu

  • Please provide enough code so others can better understand or reproduce the problem. – Community Sep 07 '22 at 09:56
  • if it's a custom menu, then you don't want contextual menu displayed, you want your custom menu displayed. There are plenty tutorials that shows that, e.g.: https://medium.com/@prathamsalvi27/ios-swift-dropdown-menu-3b2a69c34b23 – timbre timbre Sep 07 '22 at 16:23
  • @khjfquantumjj Hey thanks for reply, It is not custom, actually I want to modify this UIContextMenuInteractionDelegate, I want to change it's default text and icon alignment – Pushkar Pandey Sep 08 '22 at 04:55

0 Answers0