Creating a custom UI view class to use as a map an

2019-03-03 22:43发布

问题:

I created a custom UIView using storyboard. I don't want this at the coordinates that it is in in my storyboard, but I want to be able to reuse it throughout my app at different locations on a map like this. I also want to be able to update the text in there at the users request, and the number in there should increase whenever the green button is clicked. I also want to customize the image below it, like I learned in this question so that the user annotation has an image and this callout above it. The callout would only be there if the user has posted some text. It would look like this.

My previously linked example uses a method called setcenter to place the coordinate in the middle of the annotation, but it looks like the MGLMapView documentation and uiview documentation contain at most a setcentercoordinate function, so this is why I tried creating the annotation in storyboard instead of coding it in swift, because I didn't know how to add things to the annotation. It also doesn't look like that example show's how to constrain views to the bottom corners, like I did with my buttons (There is one view for the rocket and person button, and one view for the arrow button and the number).

Because I want to update the text field and that number(which is a label), I don't know if storyboard is the best idea to create this. I also don't know if I can use a storyboard object at a dynamic location, and create multiple of them throughout the map