CPDFThumbnailViewCell.m 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // PDFThumbnailViewCell.m
  3. // ComPDFKit_Tools
  4. //
  5. // Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  8. // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  9. // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  10. // This notice may not be removed from this file.
  11. //
  12. #import "CPDFThumbnailViewCell.h"
  13. @implementation CPDFThumbnailViewCell
  14. - (instancetype)initWithFrame:(CGRect)frame {
  15. if (self = [super initWithFrame:frame]) {
  16. _imageView = [[UIImageView alloc] init];
  17. _imageView.layer.borderWidth = 1.0;
  18. _imageView.layer.borderColor = [UIColor colorWithRed:221/255.0 green:233/255.0 blue:255/255.0 alpha:1.0].CGColor;
  19. [self.contentView addSubview:_imageView];
  20. _textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, frame.size.height - 12, frame.size.width, 12)];
  21. _textLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
  22. _textLabel.textAlignment = NSTextAlignmentCenter;
  23. _textLabel.font = [UIFont systemFontOfSize:13];
  24. _textLabel.textColor = [UIColor blackColor];
  25. [self.contentView addSubview:_textLabel];
  26. }
  27. return self;
  28. }
  29. - (void)layoutSubviews {
  30. _imageView.frame = CGRectMake((self.frame.size.width - self.imageSize.width)/2, (self.frame.size.height - 14 - self.imageSize.height) / 2, self.imageSize.width, self.imageSize.height);
  31. CGFloat startW = [self.textLabel.text sizeWithFont:[UIFont systemFontOfSize:10] constrainedToSize:CGSizeMake(MAXFLOAT, 12)].width;
  32. //restSize
  33. _textLabel.frame = CGRectMake(self.frame.size.width/2 - (startW + 20)/2, self.imageSize.height + (self.frame.size.height - 14 - self.imageSize.height) / 2, startW + 20, 12);
  34. }
  35. - (void)setPageRef:(CGPDFPageRef)pageRef {
  36. CGRect boxRect = CGRectZero;
  37. if (pageRef) {
  38. boxRect = CGPDFPageGetBoxRect(pageRef, kCGPDFCropBox);
  39. CGRect displayBounds = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height - 12);
  40. CGAffineTransform transform = CGPDFPageGetDrawingTransform(pageRef,
  41. kCGPDFCropBox,
  42. displayBounds,
  43. 0,
  44. true);
  45. boxRect = CGRectApplyAffineTransform(boxRect, transform);
  46. }
  47. }
  48. - (void)setSelected:(BOOL)selected {
  49. [super setSelected:selected];
  50. if (selected) {
  51. self.textLabel.backgroundColor = [UIColor colorWithRed:20./255 green:96./255 blue:243./255 alpha:1];
  52. self.textLabel.textColor = [UIColor whiteColor];
  53. self.imageView.layer.borderColor = [UIColor colorWithRed:20./255 green:96./255 blue:243./255 alpha:1].CGColor;
  54. self.imageView.layer.borderWidth = 2;
  55. self.imageView.layer.cornerRadius = 4;
  56. self.imageView.clipsToBounds = YES;
  57. } else {
  58. self.textLabel.backgroundColor = [UIColor clearColor];
  59. self.textLabel.textColor = [UIColor blackColor];
  60. self.imageView.layer.borderColor = [UIColor colorWithRed:242/255. green:242/255. blue:242/255. alpha:1.].CGColor;
  61. self.imageView.layer.borderWidth = 1;
  62. }
  63. }
  64. @end