Saturday 15 January 2011

ios - Drawing Polygons in Swift -



ios - Drawing Polygons in Swift -

i need highlight irregular shape when user taps on it. thought on how draw polygon matches shape, fill color , alter opacity create translucent. unfortunately can't find on how this. essentially, want draw filled polygon, overlay on map , able dismiss (or hide) it. how can accomplish this?

you want utilize cashapelayer. here's demo:

import xcplayground import uikit import coretext allow view = uiview(frame: cgrectmake(0, 0, 300, 300)) xcpshowview("view", view) allow imageview = uiimageview(image: uiimage(named: "profile.jpg")) imageview.frame = view.bounds imageview.contentmode = uiviewcontentmode.scaleaspectfill view.addsubview(imageview) allow shape = cashapelayer() view.layer.addsublayer(shape) shape.opacity = 0.5 shape.linewidth = 2 shape.linejoin = kcalinejoinmiter shape.strokecolor = uicolor(hue: 0.786, saturation: 0.79, brightness: 0.53, alpha: 1.0).cgcolor shape.fillcolor = uicolor(hue: 0.786, saturation: 0.15, brightness: 0.89, alpha: 1.0).cgcolor allow path = uibezierpath() path.movetopoint(cgpointmake(120, 20)) path.addlinetopoint(cgpointmake(230, 90)) path.addlinetopoint(cgpointmake(240, 250)) path.addlinetopoint(cgpointmake(40, 280)) path.addlinetopoint(cgpointmake(100, 150)) path.closepath() shape.path = path.cgpath

result:

ios swift drawing polygons

No comments:

Post a Comment