PPImageScrollingTableViewCell.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // PPScrollingTableViewCell.m
  3. // PPImageScrollingTableViewControllerDemo
  4. //
  5. // Created by popochess on 13/8/10.
  6. // Copyright (c) 2013年 popochess. All rights reserved.
  7. //
  8. #import "PPImageScrollingTableViewCell.h"
  9. #import "PPImageScrollingCellView.h"
  10. #define kScrollingViewHieght 120
  11. #define kCategoryLabelWidth 200
  12. #define kCategoryLabelHieght 30
  13. #define kStartPointY 30
  14. @interface PPImageScrollingTableViewCell() <PPImageScrollingViewDelegate>
  15. @property (strong,nonatomic) UIColor *categoryTitleColor;
  16. @property(strong, nonatomic) PPImageScrollingCellView *imageScrollingView;
  17. @property (strong, nonatomic) NSString *categoryLabelText;
  18. @end
  19. @implementation PPImageScrollingTableViewCell
  20. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  21. {
  22. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  23. if (self) {
  24. // Initialization code
  25. [self initialize];
  26. }
  27. return self;
  28. }
  29. - (void)awakeFromNib
  30. {
  31. [super awakeFromNib];
  32. [self initialize];
  33. }
  34. - (void)initialize
  35. {
  36. // Set ScrollImageTableCellView
  37. _imageScrollingView = [[PPImageScrollingCellView alloc] initWithFrame:CGRectMake(0., kStartPointY, 320., kScrollingViewHieght)];
  38. _imageScrollingView.delegate = self;
  39. }
  40. - (void)setSelected:(BOOL)selected animated:(BOOL)animated
  41. {
  42. [super setSelected:selected animated:animated];
  43. // Configure the view for the selected state
  44. }
  45. - (void)setImageData:(NSDictionary*)collectionImageData
  46. {
  47. [_imageScrollingView setImageData:[collectionImageData objectForKey:@"images"]];
  48. _categoryLabelText = [collectionImageData objectForKey:@"category"];
  49. }
  50. - (void)setCategoryLabelText:(NSString*)text withColor:(UIColor*)color{
  51. if ([self.contentView subviews]){
  52. for (UIView *subview in [self.contentView subviews]) {
  53. [subview removeFromSuperview];
  54. }
  55. }
  56. UILabel *categoryTitle = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, kCategoryLabelWidth, kCategoryLabelHieght)];
  57. categoryTitle.textAlignment = NSTextAlignmentLeft;
  58. categoryTitle.text = text;
  59. categoryTitle.textColor = color;
  60. categoryTitle.backgroundColor = [UIColor clearColor];
  61. [self.contentView addSubview:categoryTitle];
  62. }
  63. - (void) setImageTitleLabelWitdh:(CGFloat)width withHeight:(CGFloat)height {
  64. [_imageScrollingView setImageTitleLabelWitdh:width withHeight:height];
  65. }
  66. - (void) setImageTitleTextColor:(UIColor *)textColor withBackgroundColor:(UIColor *)bgColor{
  67. [_imageScrollingView setImageTitleTextColor:textColor withBackgroundColor:bgColor];
  68. }
  69. - (void)setCollectionViewBackgroundColor:(UIColor *)color{
  70. _imageScrollingView.backgroundColor = color;
  71. [self.contentView addSubview:_imageScrollingView];
  72. }
  73. #pragma mark - PPImageScrollingViewDelegate
  74. - (void)collectionView:(PPImageScrollingCellView *)collectionView didSelectImageItemAtIndexPath:(NSIndexPath*)indexPath {
  75. [self.delegate scrollingTableViewCell:self didSelectImageAtIndexPath:indexPath atCategoryRowIndex:self.tag];
  76. }
  77. @end