Crop square image in hexagons with quick

How can we crop a square image in hexagons using swift. I want to use a square image and crop / clip to a hexagon. EG. Chart profile picture (but in hexagons instead of circle) in swift

+3


source to share


1 answer


You will need to create a shape and save it as an image and then create an image mask. This is part of the code I used to do the same, but you will need to create your own size and straight variables. Hope this helps.



UIGraphicsBeginImageContext(size)
UIImage(CGImage: originalImage!).drawInRect(rect)
maskImage.drawInRect(rect, blendMode: CGBlendMode.DestinationIn, alpha: 1.0)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
imageView.image = newImage

      

+1


source







All Articles