Skip to content

Instantly share code, notes, and snippets.

@Pretz
Last active November 14, 2017 22:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pretz/bf6e478757a465542ce7 to your computer and use it in GitHub Desktop.
Save Pretz/bf6e478757a465542ce7 to your computer and use it in GitHub Desktop.
Render a view at 2x scale factor in an Xcode playground
func retinaWrap(view: UIView, scaleFactor: CGFloat = 2.0) -> UIView {
let scaleTransform = CGAffineTransformMakeScale(scaleFactor, scaleFactor)
let scaledView = UIView(frame: CGRectMake(0, 0, view.bounds.width * scaleFactor, view.bounds.height * scaleFactor))
view.transform = scaleTransform
view.center = CGPoint(x: scaledView.frame.width / 2, y: scaledView.frame.height / 2)
scaledView.addSubview(view)
return scaledView
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment