I'm creating an image from a text field and I'm wanting to scale up the newly created image when a user pinches/zooms. The problem I'm getting is that the quality of the image becomes pixelated and I can't seem to think of a fix.
func imageFromTextfield(text: UITextField) -> UIView {
UIGraphicsBeginImageContextWithOptions(text.intrinsicContentSize, false, UIScreen.main.scale)
text.drawHierarchy(in: text.bounds, afterScreenUpdates: true)
if let image = UIGraphicsGetImageFromCurrentImageContext() {
UIGraphicsEndImageContext()
// Draggable view returns the pinch gesture
let textImage: DraggableView = {
let view = DraggableView(frame: CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height))
view.stickerImage.frame = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height)
view.stickerImage.image = image
view.contentMode = .scaleAspectFit
view.clipsToBounds = false
view.layer.masksToBounds = false
view.translatesAutoresizingMaskIntoConstraints = false
view.stickerImage.translatesAutoresizingMaskIntoConstraints = true
return view
}()
return textImage
}
return UIView()
}
I've tried increasing the font size and scaling down the frame but this doesn't work. How can I solve this?