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