Updated 18 December 2016
Some Times we need to make images round in UITableview (Here we have not taken any UITableviewcell) , Objective C provide default feature to add images as well as round the images.
I have given code snippet .
UITableView delegate method where we are setting the Label and Images.
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
- (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 = NO; 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:@"FFFFFF"]; //cell.textLabel.textColor = [GlobalData colorWithHexString:@"FFFFFF"]; //cell.backgroundView = backgroundView; } } } if(indexPath.section == 0){ cell.imageView.layer.cornerRadius = 25.0f; cell.imageView.layer.borderWidth = 2.0f; cell.imageView.layer.borderColor = [UIColor whiteColor].CGColor; cell.imageView.clipsToBounds = YES; cell.imageView.image = [self imageWithImage:[UIImage imageNamed:@"ic_placeholder.jpg"] scaledToSize:CGSizeMake(50,50)]; for(int i = 0; i < [categoryImagesId count]; i++){ if([[categoryImagesId objectAtIndex:i] isEqualToString:[categoryId objectAtIndex:[indexPath row]]]){ UIImage *imageIcon = [imageCache objectForKey:[categoryImages objectAtIndex:[indexPath row]]]; if(imageIcon){ cell.imageView.image = [self imageWithImage:imageIcon scaledToSize:CGSizeMake(50,50)]; } else{ GlobalData *obj = [GlobalData getInstance]; [_queue addOperationWithBlock:^{ UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[categoryImages objectAtIndex:[indexPath row ]]]]]; if(image){ [[NSOperationQueue mainQueue] addOperationWithBlock:^{ cell.imageView.image = [self imageWithImage:imageIcon scaledToSize:CGSizeMake(50,50)]; }]; [obj.gloablCatalogIconCache setObject:image forKey:[categoryImages objectAtIndex:[indexPath row]]]; } }]; } break; } } } else if(indexPath.section == 2){ cell.imageView.layer.cornerRadius = 25.0f; cell.imageView.layer.borderWidth = 2.0f; cell.imageView.layer.borderColor = [UIColor whiteColor].CGColor; cell.imageView.clipsToBounds = YES; if([indexPath row] == 0) cell.imageView.image = [self imageWithImage:[UIImage imageNamed:@"ic_search_term"] scaledToSize:CGSizeMake(50,50)]; if([indexPath row] == 1) cell.imageView.image = [self imageWithImage:[UIImage imageNamed:@"ic_advance_search"] scaledToSize:CGSizeMake(50,50)]; if([indexPath row] == 2) cell.imageView.image = [self imageWithImage:[UIImage imageNamed:@"nav_ic_marketplace"] scaledToSize:CGSizeMake(50,50)]; } else cell.imageView.image = [UIImage imageNamed:@""]; cell.textLabel.text = contentForThisRow; if([[languageCode stringForKey:@"language" ] isEqualToString:@"ar"]) cell.textLabel.textAlignment = NSTextAlignmentRight; return cell; } |
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.