How can I flip a shortcut (get a mirror image) in Swift (Xcode 6.3)
I am trying to flip (mirror) the text of a label using CGAffineTransformMakeRotation. But there is no progress yet.
This code flips it vertically, but I couldn't flip it horizontally.
self.labelShowdata.transform = CGAffineTransformMakeRotation((180.0 * CGFloat(M_PI)) / 180.0)
thank
+3
source to share
4 answers
Quick extension to flip vertically or horizontally any UIView:
extension UIView {
/// Flip view horizontally.
func flipX() {
transform = CGAffineTransform(scaleX: -transform.a, y: transform.d)
}
/// Flip view vertically.
func flipY() {
transform = CGAffineTransform(scaleX: transform.a, y: -transform.d)
}
}
Usage:
yourView.flipX()
oryourView.flipY()
+5
source to share