Updated 18 December 2016
Sometimes we need to change the position of the image in given UItableview , normally in UITable view image are situated in left position in default UITableView so we can change the alignment of  Text but for Image , we require custom UITableView so without creating a customize UITableView , you can customize default UITableView according to your need.
I have  implemented  this for creating an Arabic storyboard on that time change from left to right with image also.
code snippet:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } NSArray *sectionContents = [allData objectAtIndex:[indexPath section]]; NSString *contentForThisRow = [sectionContents objectAtIndex:[indexPath row]]; if(indexPath.section == 1){ NSArray* firstSplittedTest = [contentForThisRow componentsSeparatedByString: @"-_-"]; contentForThisRow = firstSplittedTest[0]; NSArray* secondSplittedTest = [firstSplittedTest[0] componentsSeparatedByString: @" "]; if([secondSplittedTest count] == 1) cell.userInteractionEnabled = YES; else if([secondSplittedTest count] > 1){ cell.tag = [firstSplittedTest[1] integerValue]; NSString *tappedTag = [NSString stringWithFormat:@"%d", (int)[firstSplittedTest[1] integerValue]]; NSString *storeId = [preferences objectForKey:@"storeId"]; if([tappedTag isEqualToString:storeId]){ UIView *backgroundView = [[UIView alloc] init]; backgroundView.backgroundColor = [GlobalData colorWithHexString:@"268ED7"]; cell.textLabel.textColor = [GlobalData colorWithHexString:@"FFFFFF"]; cell.backgroundView = backgroundView; } } } if(indexPath.section == 0){ cell.imageView.image = [UIImage imageNamed:@"ic_placeholder.png"]; for(int i = 0; i < [categoryImagesId count]; i++){ if([[categoryImagesId objectAtIndex:i] isEqualToString:[categoryId objectAtIndex:[indexPath row]]]){ UIImage *imageIcon = [imageCache objectForKey:[categoryImages objectAtIndex:i]]; if(imageIcon){ cell.imageView.image = imageIcon; } else{ GlobalData *obj = [GlobalData getInstance]; [_queue addOperationWithBlock:^{ UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[categoryImages objectAtIndex:i]]]]; if(image){ [[NSOperationQueue mainQueue] addOperationWithBlock:^{ cell.imageView.image = image; }]; [obj.gloablCatalogIconCache setObject:image forKey:[categoryImages objectAtIndex:i]]; } }]; } break; } } } else cell.imageView.image = [UIImage imageNamed:@""]; cell.textLabel.text = contentForThisRow; if([[languageCode stringForKey:@"language" ] isEqualToString:@"ar"]){ cell.textLabel.textAlignment = NSTextAlignmentRight; cell.imageView.transform = CGAffineTransformMakeScale(-1,1); cell.contentView.transform = CGAffineTransformMakeScale(-1,1); cell.textLabel.transform = CGAffineTransformMakeScale(-1,1); } return cell; } |
it will transform like mirror .
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.