CPDFOutlineViewCell.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // CPDFOutlineViewCell.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 "CPDFOutlineViewCell.h"
  13. #import "CPDFOutlineModel.h"
  14. @implementation CPDFOutlineViewCell
  15. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  16. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  17. if (self) {
  18. UIButton *arrowButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 4, 36, 26)];
  19. [arrowButton addTarget:self action:@selector(buttonItemClicked_Arrow:) forControlEvents:UIControlEventTouchUpInside];
  20. [arrowButton setImage:[UIImage imageNamed:@"CPDFOutlineImageBotaMore" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateSelected];
  21. [arrowButton setImage:[UIImage imageNamed:@"CPDFOutlineImageBotaMoreLeft" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  22. _arrowButton = arrowButton;
  23. UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(70 + self.offsetX.constant, 0, self.bounds.size.width - self.offsetX.constant - 120, 26)];
  24. _nameLabel = nameLabel;
  25. _nameLabel.font = [UIFont systemFontOfSize:14.];
  26. UILabel *countLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.bounds.size.width-55, 0, 50, 26)];
  27. countLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  28. _countLabel = countLabel;
  29. _countLabel.font = [UIFont systemFontOfSize:14.];
  30. [self.contentView addSubview:arrowButton];
  31. [self.contentView addSubview:nameLabel];
  32. [self.contentView addSubview:countLabel];
  33. }
  34. return self;
  35. }
  36. - (void)setOutline:(CPDFOutlineModel *)outline {
  37. if (_outline != outline) {
  38. _outline = outline;
  39. }
  40. self.nameLabel.text = outline.title;
  41. self.countLabel.text = [NSString stringWithFormat:@"%ld", outline.number + 1];
  42. self.offsetX.constant = 10 * outline.level;
  43. if (outline.count>0) {
  44. [self.arrowButton setHidden:NO];
  45. if (outline.isShow) {
  46. self.arrowButton.selected = YES;
  47. } else {
  48. self.arrowButton.selected = NO;
  49. }
  50. } else{
  51. [self.arrowButton setHidden:YES];
  52. }
  53. self.nameLabel.frame = CGRectMake(25 + 10 * outline.level,10, self.bounds.size.width - self.offsetX.constant - 100, 16);
  54. self.countLabel.frame = CGRectMake(self.bounds.size.width-55, 10, 55, 14);
  55. }
  56. - (void)setIsShow:(BOOL)isShow {
  57. _isShow = isShow;
  58. self.outline.isShow = self.isShow;
  59. if (self.outline.count>0) {
  60. if (self.outline.isShow) {
  61. self.arrowButton.selected = YES;
  62. } else {
  63. self.arrowButton.selected = NO;
  64. }
  65. }
  66. }
  67. - (void)awakeFromNib {
  68. [super awakeFromNib];
  69. // Initialization code
  70. }
  71. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  72. [super setSelected:selected animated:animated];
  73. // Configure the view for the selected state
  74. }
  75. #pragma mark - Action
  76. - (void)buttonItemClicked_Arrow:(id)sender {
  77. if ([self.delegate respondsToSelector:@selector(buttonItemClicked_Arrow:)]) {
  78. [self.delegate buttonItemClicked_Arrow:self];
  79. }
  80. }
  81. @end