Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I flip a UILabel horizontally?

Tags:

cocoa-touch

I want to develop an iPhone application using the utility template, where the flip side is semi-transparent displaying the contents of the main view, flipped horizontally.

Edit: To create the illusion of semi-transparent flip side, I'd display the same content on the flip view as in the main view, but mirror the content and lower the alpha.

Is it possible to display a text using an UILabel, but mirror the text, ie flip it horizontally? Apple dev pages does not give me any help in this issue.

like image 891
Fredrik Telenius Avatar asked Dec 01 '22 12:12

Fredrik Telenius


1 Answers

As August said, I'm not sure of your use case on this, but there's a reasonably straightforward way to do it using Core Animation. First, you'll need to add the QuartzCore framework to your project and do a

#import <QuartzCore/QuartzCore.h>

somewhere in your headers.

Then, you can apply a rotational transform to your UILabel's underlying layer using the following:

yourLabel.layer.transform = CATransform3DMakeRotation(M_PI, 0.0f, 1.0f, 0.0f);

which will rotate the label's CALayer by 180 degrees (pi radians) about the Y axis, producing the mirror effect you're looking for.

like image 149
Brad Larson Avatar answered Aug 10 '23 21:08

Brad Larson