Hi Readers,
This blog will display the collection view content in Right To Left language such as Hebrew/ Arabic. Generally, you will see the collection view as displayed in the below screenshot.
To set UICollectionView right align first make a property of UICollectionView
example ->
@property (weak, nonatomic) IBOutlet UICollectionView *myCollectionView;
After this add following code to "viewDidLoad"
- (void)viewDidLoad {
[super viewDidLoad];
[self.myCollectionView setTransform:CGAffineTransformMakeScale(-1, 1)];
// Do any additional setup after loading the view.
}
Now you will see mirror image of your collection view along with right align cell , like in below screenshot.
Now to remove this strange mirror effect,don’t forget to add below line to add in “cellForItemAtIndexPath”.
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
DemoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DemoCollectionViewCell" forIndexPath:indexPath];
[cell.contentView setTransform:CGAffineTransformMakeScale(-1, 1)];
NSString *str = [NSString stringWithFormat:@"%ld",(long)indexPath.row];
NSString *mainStr = @"Label ";
mainStr = [mainStr stringByAppendingString:str];
[cell.labelTxt setText:mainStr];
return cell;
}
Now run your app, and you will see output like following screenshot.
1 Comment(s)