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


Try the following:



self.labelShowdata.transform = CGAffineTransformMakeScale(-1, 1);

      

+15


source


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


If you need mirroring, you must use CGAffineTransformMakeScale:

self.labelShowdata.transform = CGAffineTransformMakeScale(-1., 1);

      

+3


source


For Swift 3 based on @ Choppin Broccoli's solution:

self.labelShowdata.transform = CGAffineTransform(scaleX: -1, y: 1)

      

+1


source







All Articles