How can I flip a label (get the mirror view) in Swift (Xcode 6.3)
If you need a mirror view you should use CGAffineTransformMakeScale:
self.labelShowdata.transform = CGAffineTransformMakeScale(-1., 1);
For Swift 3 based on @Choppin Broccoli's solution:
self.labelShowdata.transform = CGAffineTransform(scaleX: -1, y: 1)
Swift 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()
or yourView.flipY()
Try this:
self.labelShowdata.transform = CGAffineTransformMakeScale(-1, 1);
Swift 5:
self.table.transform = CGAffineTransform(scaleX: -1, y: 1);