PDFSettingFontView.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // PDFSettingFontView.m
  3. // PDFReader
  4. //
  5. // Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // The PDF Reader Sample applications are licensed with a modified BSD license.
  8. // Please see License for details. This notice may not be removed from this file.
  9. //
  10. #import "PDFSettingFontView.h"
  11. @interface PDFSettingFontView ()
  12. @property (nonatomic, assign) NSInteger minValue;
  13. @property (nonatomic, assign) NSInteger maxValue;
  14. @property (nonatomic, retain) UITableView *tableView;
  15. @end
  16. @implementation PDFSettingFontView
  17. - (id)initWithFrame:(CGRect)frame
  18. minValue:(NSInteger)minValue
  19. maxValue:(NSInteger)maxValue{
  20. self = [super initWithFrame:frame];
  21. self.minValue = minValue;
  22. self.maxValue = maxValue;
  23. if (self) {
  24. _tableView = [[UITableView alloc] initWithFrame:self.bounds];
  25. _tableView.delegate = self;
  26. _tableView.dataSource = self;
  27. _tableView.separatorInset = UIEdgeInsetsZero;
  28. _tableView.backgroundColor = [UIColor clearColor];
  29. _tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
  30. [self addSubview:_tableView];
  31. }
  32. return self;
  33. }
  34. - (void)dealloc
  35. {
  36. _fontNamedelegate = nil;
  37. _tableView.delegate = nil;
  38. _tableView.dataSource = nil;
  39. [_tableView release];
  40. [super dealloc];
  41. }
  42. - (void)setCurValue:(NSInteger)curValue
  43. {
  44. _curValue = curValue;
  45. [_tableView reloadData];
  46. NSInteger row = self.curValue - self.minValue;
  47. NSIndexPath * indexPath = [NSIndexPath indexPathForRow:row inSection:0];
  48. [_tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
  49. }
  50. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  51. {
  52. self.curValue = _minValue + indexPath.row;
  53. if ([_fontNamedelegate respondsToSelector:@selector(fontNamesView:didSelectedTextFontName:)]) {
  54. [_fontNamedelegate fontNamesView:self didSelectedTextsize:(_minValue + indexPath.row)];
  55. }
  56. }
  57. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  58. return 1;
  59. }
  60. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  61. return _maxValue - _minValue + 1;
  62. }
  63. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  64. return 40;
  65. }
  66. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  67. {
  68. static NSString *CellIdentifier = @"FontNameCell";
  69. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  70. if (cell == nil) {
  71. cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
  72. cell.backgroundColor = [UIColor clearColor];
  73. }
  74. cell.textLabel.text = [NSString stringWithFormat:@"%@",@(_minValue + indexPath.row)];
  75. if (self.curValue == _minValue + indexPath.row) {
  76. cell.accessoryType = UITableViewCellAccessoryCheckmark;
  77. } else {
  78. cell.accessoryType = UITableViewCellAccessoryNone;
  79. }
  80. cell.backgroundColor = [UIColor clearColor];
  81. return cell;
  82. }
  83. @end