PPCollectionViewCell.m 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // PPCollectionViewCell.m
  3. // PPImageScrollingTableViewControllerDemo
  4. //
  5. // Created by popochess on 13/8/10.
  6. // Copyright (c) 2013年 popochess. All rights reserved.
  7. //
  8. #import "PPCollectionViewCell.h"
  9. @interface PPCollectionViewCell ()
  10. @property (strong, nonatomic) UIImageView *imageView;
  11. @property (strong, nonatomic) UITextView *imageTitle;
  12. @end
  13. @implementation PPCollectionViewCell
  14. - (id)initWithFrame:(CGRect)frame
  15. {
  16. self = [super initWithFrame:frame];
  17. if (self) {
  18. // Initialization code
  19. self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0., 0., frame.size.width, frame.size.height)];
  20. }
  21. return self;
  22. }
  23. -(void)setImage:(UIImage *)image
  24. {
  25. self.imageView.image = image;
  26. }
  27. - (void)setImageTitleLabelWitdh:(CGFloat)width withHeight:(CGFloat)height
  28. {
  29. self.imageTitle = [[UITextView alloc] initWithFrame:CGRectMake(0., _imageView.frame.size.height/2+5, width,height)];
  30. self.imageTitle.contentInset = UIEdgeInsetsMake(1,1,1,1);
  31. self.imageTitle.userInteractionEnabled = NO;
  32. }
  33. - (void)setImageTitleTextColor:(UIColor*)textColor withBackgroundColor:(UIColor*)bgColor
  34. {
  35. self.imageTitle.textColor = textColor;
  36. self.imageTitle.backgroundColor = bgColor;
  37. }
  38. - (void)setTitle:(NSString*)title ;
  39. {
  40. if ([self.contentView subviews]){
  41. for (UILabel *subview in [self.contentView subviews]) {
  42. [subview removeFromSuperview];
  43. }
  44. }
  45. [self.contentView addSubview:self.imageView];
  46. self.imageTitle.text = title;
  47. [self.contentView addSubview:self.imageTitle];
  48. }
  49. /*
  50. // Only override drawRect: if you perform custom drawing.
  51. // An empty implementation adversely affects performance during animation.
  52. - (void)drawRect:(CGRect)rect
  53. {
  54. // Drawing code
  55. }
  56. */
  57. @end