Draw text in circle overlay

后端 未结 3 602
生来不讨喜
生来不讨喜 2020-11-30 11:23

I\'m trying to draw some circle overlays containing text on MKMapView. I have subclassed the MKCircleView, in which I put the following (based on this), but the text does no

3条回答
  •  春和景丽
    2020-11-30 12:02

    I believe your code is working and the problem is that the text is not being scaled properly making it invisible.

    Scale the font size based on the zoomScale using the MKRoadWidthAtZoomScale function:

    [t drawInRect:overallCGRect withFont:[UIFont fontWithName:@"Arial" 
        size:(10.0 * MKRoadWidthAtZoomScale(zoomScale))] 
        lineBreakMode:UILineBreakModeClip alignment:UITextAlignmentCenter];
    

    Also be sure to use a text color that's different from the underlying circle's color.

    Note that using drawInRect will result in the text being restricted to inside the circle and may get truncated. If you want to always show all the text, you could use drawAtPoint instead.

提交回复
热议问题