ios - MKMarkerAnnotationView has a truncated image -


i want uiimage mkmarkerannotationview following code image truncated (at top , bottom, see screenshot)

let newannotation = simpleannotation(sourcecoordinate: annotation.coordinate, sourcetitle: "hello", sourcesubtitle: "world") let pinannotation = mkmarkerannotationview(annotation: newannotation, reuseidentifier: "test") pinannotation.markertintcolor = uicolor.red pinannotation.glyphtext = "1" pinannotation.animateswhenadded = false pinannotation.glyphtintcolor = uicolor.white pinannotation.titlevisibility = .hidden pinannotation.subtitlevisibility = .hidden  uigraphicsbeginimagecontextwithoptions(pinannotation.bounds.size, false, 0.0) pinannotation.drawhierarchy(in: cgrect(x:0,                                        y:0,                                        width:pinannotation.bounds.width,                                        height:pinannotation.bounds.height),                             afterscreenupdates: true) let snapshotimagefrommyview = uigraphicsgetimagefromcurrentimagecontext() uigraphicsendimagecontext() 

any idea why it's truncated? in xcode debugger can see image truncated in pinannotation (before use uigraphics... uiimage)

enter image description here

i have found solution! have set contentmode scaleaspectfit , change bounds size of image need (40x40px).

here's code displaying full mkmarkerannotationview.

let pinannotation = mkmarkerannotationview() pinannotation.markertintcolor = uicolor.red pinannotation.glyphtext = "1" pinannotation.animateswhenadded = false pinannotation.glyphtintcolor = uicolor.white pinannotation.titlevisibility = .hidden pinannotation.subtitlevisibility = .hidden pinannotation.contentmode = .scaleaspectfit pinannotation.bounds = cgrect(x: 0, y: 0, width: 40, height: 40)  uigraphicsbeginimagecontextwithoptions(pinannotation.bounds.size, false, 0.0) pinannotation.drawhierarchy(in: cgrect(x:0,                                        y:0,                                        width:pinannotation.bounds.width,                                        height:pinannotation.bounds.height),                             afterscreenupdates: true) let snapshotimagefrommyview = uigraphicsgetimagefromcurrentimagecontext() uigraphicsendimagecontext() 

this page demystifying ios layout has helped me lot find solution.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -