Advertisement
Guest User

Untitled

a guest
Jul 31st, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  2.  
  3. static NSString *MyIdentifier = @"cell1";
  4. NSDictionary *categoryDictionary= [[appdelegate categoriesArray] objectAtIndex:indexPath.row];
  5.  
  6. categoryTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
  7.  
  8. rect=cell.labelProgressView.frame;
  9. cell.backgroundColor = [UIColor PGColorBackground];
  10.  
  11. cell.buttonView.hidden=YES;
  12.  
  13.  
  14. //Set background colors and icons
  15. switch ([[categoryDictionary valueForKey:@"categoryID"] intValue])
  16. {
  17. case 1:
  18. [cell.buttonView setBackgroundColor: [UIColor PGColorAttractions]] ;
  19. [cell.labelProgressView setBackgroundColor: [UIColor PGColorAttractions]] ;
  20. [cell.ivCategoryBannerImage setImage: [UIImage imageNamed:@"attraction-bg"]];
  21. cell.ivcategoryLogoImage.image =[UIImage imageNamed:@"attractionWhite"];
  22. break;
  23. case 2:
  24. [cell.buttonView setBackgroundColor: [UIColor PGColorRestaurants]];
  25. [cell.labelProgressView setBackgroundColor: [UIColor PGColorRestaurants]];
  26. [cell.ivCategoryBannerImage setImage: [UIImage imageNamed:@"restaurant-bg"]];
  27. cell.ivcategoryLogoImage.image =[UIImage imageNamed:@"restaurantWhite"];
  28. break;
  29. case 3:
  30. [cell.buttonView setBackgroundColor: [UIColor PGColorShopping]];
  31. [cell.labelProgressView setBackgroundColor:[UIColor PGColorShopping]];
  32. [cell.ivCategoryBannerImage setImage: [UIImage imageNamed:@"shopping-bg"]];
  33. cell.ivcategoryLogoImage.image =[UIImage imageNamed:@"shoppingWhite"];
  34. break;
  35. case 4:
  36. [cell.buttonView setBackgroundColor: [UIColor PGColorAccomodations]];
  37. [cell.labelProgressView setBackgroundColor:[UIColor PGColorAccomodations]];
  38. [cell.ivCategoryBannerImage setImage: [UIImage imageNamed:@"accomodation-bg"]];
  39. cell.ivcategoryLogoImage.image =[UIImage imageNamed:@"accomodationWhite"];
  40. break;
  41.  
  42. case 5:
  43. [cell.buttonView setBackgroundColor: [UIColor PGColorArtGalleries]];
  44. [cell.labelProgressView setBackgroundColor:[UIColor PGColorArtGalleries]];
  45. [cell.ivCategoryBannerImage setImage: [UIImage imageNamed:@"artGallery-bg"]];
  46. cell.ivcategoryLogoImage.image =[UIImage imageNamed:@"artGalleryWhite"];
  47. break;
  48.  
  49. default:
  50. break;
  51.  
  52. }
  53.  
  54. //DOWNLOAD Button
  55. [cell.buttonViewDownload setBackgroundColor:[UIColor clearColor]];
  56. cell.buttonViewDownload.layer.borderColor=[UIColor whiteColor].CGColor;
  57. cell.buttonViewDownload.layer.borderWidth=1.0f;
  58. [cell.buttonViewDownload.titleLabel setFont:[UIFont fontWithName:@"OpenSans-Bold" size:10]];
  59. [cell.buttonViewDownload setTag:[[categoryDictionary valueForKey:@"categoryID"] intValue]];
  60.  
  61. //VIEW Button
  62. cell.buttonView.layer.borderColor=[UIColor whiteColor].CGColor;
  63. cell.buttonView.layer.borderWidth=1.0f;
  64. [cell.buttonView.titleLabel setFont:[UIFont fontWithName:@"OpenSans-Bold" size:10]];
  65. [cell.buttonView setTag:[[categoryDictionary valueForKey:@"categoryID"] intValue]];
  66. [cell.buttonView addTarget:self action:@selector(viewbuttonClicked:) forControlEvents:UIControlEventTouchUpInside];
  67.  
  68. //CATEGORY label
  69.  
  70. NSString *categoryName =[[NSString stringWithFormat:@"%@",[categoryDictionary valueForKey:@"categoryNameen"]] uppercaseString];
  71.  
  72. NSMutableAttributedString *attributedString;
  73. attributedString = [[NSMutableAttributedString alloc] initWithString:categoryName];
  74.  
  75. [attributedString addAttribute:NSKernAttributeName
  76. value:[NSNumber numberWithFloat:8.0]
  77. range:NSMakeRange(0, [categoryName length])];
  78.  
  79. [attributedString addAttribute:NSFontAttributeName
  80. value:[UIFont fontWithName:@"OpenSans-Bold" size:19]
  81. range:NSMakeRange(0, [categoryName length])];
  82.  
  83.  
  84. [cell.labelCategory setAttributedText:attributedString];
  85.  
  86. cell.selectionStyle=UITableViewCellAccessoryNone;
  87.  
  88. //Set State
  89.  
  90. cell.ivCategoryBannerImage.alpha =0.1f;
  91.  
  92. BOOL isAvailable = [[categoryDictionary valueForKey:@"isAvailable"] boolValue];
  93. BOOL userTappedDownload = [[categoryDictionary valueForKey:@"userTappedDownload"] boolValue];
  94.  
  95. NSLog(@"isAvailable: %d", isAvailable);
  96. NSLog(@"userTappedDownload: %d", isAvailable);
  97.  
  98. if (isAvailable && userTappedDownload)
  99. {
  100. cell.buttonView.hidden=NO;
  101. [cell.buttonView setTitle:@"VIEW" forState:UIControlStateNormal];
  102. cell.buttonViewDownload.hidden=YES;
  103. cell.ivCategoryBannerImage.alpha =1.0f;
  104. rect.size.width=208.0f;
  105. }
  106. else if(!isAvailable && !userTappedDownload)
  107. {
  108. rect.size.width=0.1f;
  109. [cell.buttonViewDownload setTitle:[NSString stringWithFormat:@"DOWNLOAD (%@ KB)",[categoryDictionary valueForKey:@"totalImagesSize"]] forState:0];
  110.  
  111. }
  112. else if(!isAvailable && userTappedDownload)
  113. {
  114. rect.size.width=[[categoryDictionary valueForKey:@"totalImagesAvailable"] intValue];
  115. [cell.buttonViewDownload setTitle:@"DOWNLOADING CONTENT" forState:UIControlStateNormal];
  116. cell.buttonViewDownload.userInteractionEnabled = NO;
  117.  
  118. }
  119.  
  120.  
  121.  
  122. return cell;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement