How does Apple add rating stars to callouts on map views? - ios

Trying to do something that shouldn't be this difficult. Trying to display stars for a rating very similar to a screenshot (below) that Apple provides in the Maps Programming Guide for iOS.
Basically in the subtitle of the Annotation callout, I want to show some stars in a different color than the rest of the text in the subtitle.
I really cannot figure out how to do this without going through the entire nonsense of creating an entirely custom callout. They provide some documentation on doing that, but I am trying to avoid it unless I really have to.
As far as I can tell, with the out of the box MKAnnotation protocol, both title and subtitle properties are just NSString...if I could use an attributed string I could make it work, but it doesn't seem possible. Is Apple "cheating" here by creating a custom callout that looks just like the "normal" one?
Will I really need to go through the process of creating an entire custom callout just to do this? I really want to keep all the existing functionality and layout of the native callout.
Thanks!

Nevering having used this library, I defer to the documentation which mentions:
To provide custom callout views, override the leftCalloutAccessoryView method and use it to return the views.
Although it's under the Subclassing heading for the class documentation, I don't think that means to subclass the entire MKAnnotationView.
The class has a leftCalloutAccessoryView property which is not listed as readonly and has a default value of nil, so presumably you'll need to at least create a custom view, and then set the MKAnnotationView.leftCalloutAccessory to it.
The MKAnnotation protocol seems to just provide limited information to be used by the MKAnnotationView

Related

Best way to create Custom (Octagonal) UIButton in Swift

I am about to customize all of my UIButtons by subclassing them into a special UIButton class and I want to have the "look and feel" like below octagonal or some hexagonal buttons. What would be the best way to create such shape UI buttons? So far, I only know how to create rectangle, circular and rounded-edge buttons, and I could not find SO answers or cocoapods for below "look and feel".
Is it possible to create a custom class of such UIButton programmatically?
Or do I need to import an image onto a button to realize below "look and feel"?
Also, could there be any possibility be that App Store does not allow such custom shape buttons?
Yes you can use UIBezierPath to create arbitrary shapes for a variety of UIKit components that includes UIButton. See tutorial here
I think the above is achievable simply using #1 above in combination with myButton.layer.borderColor/.borderWidth
I am not sure. My guess would be no but I think it would depend on the Apple Human Interface guidelines which seem to be arbitrary in some cases. For what it's worth, I've shipped apps that had very similar buttons but they were elipses and not polygons like you have but still appear very similar.
Update: Forgot about a great example. This is an example of a "bookmark tab" effect I created using a UIButton with a UIBezier path. This has been shipping for years at this point with no issues:

Make a Mapbox RMAnnotation display its callout programmatically

I'm making an iOS app (using Swift) that has a map in the Mapbox iOS SDK. I've gotten to the point of displaying several markers on the map. Now, I want the user to be able to select a marker from the list, panning to that marker (easy), which also makes the marker's callout bubble appear automatically without the user having to touch it (not so easy).
It's this last task I'm having trouble with. While I've found the RMMarker class's showLabel() method, I can't seem to directly access a RMAnnotation's associated RMMarker object, so I'm not sure where or how to call this method.
Does anyone know how this is done?
Ignore the showLabel() API — this is not the callout in use, but rather a text label that's possible directly on the annotation.
You probably want -[RMMapView selectAnnotation:animated:] with a NO in the animated argument.

MapKit overlays to add floor plans to map

I am trying to add an overlay to iOS MapKit in order to show floor plans. However, I am unsure about the best way of doing this. If I add the floor plans by using an MKOverlay, will the floor plans be loaded lazily or do I need to find out which part of the map is being displayed and update overlays thereafter? I also looked at using MKTileOverlay, as it is using lazy loading, but I have the impression that it should be used for completely covering of the map and not only to add to the existing one. Is this correct?
Yes, you are right MKTileOverlay can cover whole map with tiles and Yes it is using lazy loading.
Use MKOverlay if you are not willing to replace native look and fill of map. You can also achieve lazy loading for MKOverlay too.
Note: MKTileOverlay will not remove your already existing MKAnnotations and MKOverlay.
MKOverlay is a protocol, not a class. You want MKTileOverlay as of iOS 7. Things are lazy loaded according to what portion of the map is currently shown.
You might find this useful as a reference on how the tiles are numbered and organized:
https://www.mapbox.com/foundations/how-web-maps-work/
As for covering Apple's map, this will happen by default, but you can also adjust the MKOverlayLevel used to place it between Apple's base map and labels layer, or you can use canReplaceMapContent = YES if you want to disable Apple's maps entirely.

MKAnnotationView - Callout title or description with multiple lines?

Is it possible to display several lines in title or description/subtitle without writing your own custom annotation view, using i.e. MKPinAnnotationView?
I believe it's not possible.
What you need is to create a custom callout, and layout it the way you want. You can even mimic the native appearance.
This page can help you creating the custom callout: http://blog.asolutions.com/2010/09/building-custom-map-annotation-callouts-part-1/

Add new UIButton "state" with custom image

I'm trying to build a simple peg jumping game (see: http://cl.ly/2x0v1V3z351t0j3d3y0L).
My plan is to make each "peg" a UIButton and toggle the UIButton states for the different images that need to be displayed at different times during the game. Using the default states for UIButton gets me pretty far but I need to add one extra state beyond the default 4.
How would I go about doing this? I figure I will need to sub class UIButton to create a custom UIButton object but this is where I get stuck. I can't find any resources on adding new button states. Is this something that is possible?
This link below was a major help to me implementing my own custom button. I basically took that guy's code and made it ARC compatible, but the basic principle in what he's done really works great!
Custom Button States
Subclass UIBUtton and add a custom state variable, then use the setter to change the image that is shown.

Resources