My suggestion is to separate the image map itself from the picker. The map parts should be defined as an array of structs like this:
mapData: Struct
let path: UIBezierPath
let title: String
let description: String
There are pros and cons using this structure
Pros:
really little cost to memory,
using value types instead of objects, making it more "swifty", and
the UIBezierPath makes the part look sharp and great regardless of magnification or resolution.
Takes next to nothing in disk space
Cons:
Harder to set up
Vector paths demands the parts to be drawn in a vector based app like Illustrator, and then exported to Swift with an app like PaintCode
I think the vector based images is the proper path to go, since it is resolution and size independent, it will also be more future proof.
So with the images out of the way, the picker could just focus on selecting parts, regardless if it is the whole body, a hand, or some other group of individual parts. Also if someone does not like the design language of the standard body set of parts, it can easily work with any other design right out of the box. Its also important to use only a very limited number of public methods and properties, since the functionality of the picker should be really simple.
ImageMapPicker: UIView
public var imageMapArray: [mapData]
the imageMapArray contains an array with mapData Structs. This is set when the view is initialised.
We would need a convenience initialiser where we can pass the array of mapData Structs, like this:
init(rect: CGRect, map: [mapData])
If the picker was assigned in IB, the map has to be populated after the view is initialised, thats why the map array needs to be a var instead of let.
To get the selected data back to the view controller, the following protocol should be implemented:
ImageMapPickerDelegate protocol
var selectedPart { get }
Here the selectedPart var would contain a mapData Struct of the current selected part.
My suggestion is to separate the image map itself from the picker. The map parts should be defined as an array of structs like this:
There are pros and cons using this structure Pros:
Cons:
I think the vector based images is the proper path to go, since it is resolution and size independent, it will also be more future proof.
So with the images out of the way, the picker could just focus on selecting parts, regardless if it is the whole body, a hand, or some other group of individual parts. Also if someone does not like the design language of the standard body set of parts, it can easily work with any other design right out of the box. Its also important to use only a very limited number of public methods and properties, since the functionality of the picker should be really simple.
ImageMapPicker: UIView public var imageMapArray: [mapData]
the imageMapArray contains an array with mapData Structs. This is set when the view is initialised. We would need a convenience initialiser where we can pass the array of mapData Structs, like this:
init(rect: CGRect, map: [mapData])
If the picker was assigned in IB, the map has to be populated after the view is initialised, thats why the map array needs to be a var instead of let.
To get the selected data back to the view controller, the following protocol should be implemented:
ImageMapPickerDelegate protocol var selectedPart { get }
Here the selectedPart var would contain a mapData Struct of the current selected part.