Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flip UIImageViews for Right to Left Languages

Tags:

iOS automatically flips the entire ViewController when using a RTL language like Arabic and does a great job with most of the layout, especially text. The default behavior is to flip the layout but leave UIImageViews the same orientation (since you generally don't want to reverse images).

Is there a way to specify that some images should be flipped (such as arrows) when the phone is set to a RTL language?

like image 854
jhulst Avatar asked Dec 03 '13 14:12

jhulst


3 Answers

iOS 9 includes the imageFlippedForRightToLeftLayoutDirection method that you can use, that automatically flips the image in a UIImageView when in an RTL localization.

like image 117
wakachamo Avatar answered Oct 24 '22 00:10

wakachamo


The best solution I found to date is marking the image in the assets file as mirror. enter image description here

like image 23
SergioM Avatar answered Oct 23 '22 22:10

SergioM


We can use imageFlippedForRightToLeftLayoutDirection which returns flipped image if current language is RTL(right to left). i.e

Objective-c

UIImage * flippedImage = [[UIImage imageNamed:@"imageName"] imageFlippedForRightToLeftLayoutDirection];

Swift 3

let flippedImage = UIImage(named: "imageName")?.imageFlippedForRightToLeftLayoutDirection()

Source: Apple Docs

like image 32
Aamir Avatar answered Oct 23 '22 23:10

Aamir