How to add button on top of the image(like maps and structure of the human body) in swift

Viewed 20

Does anyone know how to make the image clickable in different area, like maps, structure of the human body in Swift and suitable for iPhone and iPad in difference resolution.

for example,

There is an image of human body,I would like to make head, body, hands and legs clickable. I wonder is it possible to create a transparent button on top of the image and redirect to another views(navigationLink).

Also, Is offset suitable for iPhone and iPad in difference resolution?

Dose anyone can give me some hints?

Thanks a lot

1 Answers

For different actions for different areas of the image, I recommend you to separate this image and then create a button with the image inside, that's the most logical and safe to do.

But if you have an imageView and want to make it clickable, you can do the following.

Where you set up the image, do this:

imageView.addTarget(self, action: #selector(didTapImage), for: .touchUpInside)

and then, create the function for the action:

@objc
func didTapImage() {
    // your code here
}
Related