need to change UIGraphicsBeginImageContext(self.frame.size) with UIGraphicsBeginImageContextWithOptions(self.frame.size, false, UIScreen.main.scale)
need to change
UIGraphicsBeginImageContext(self.frame.size)
with
UIGraphicsBeginImageContextWithOptions(self.frame.size, false, UIScreen.main.scale)