PDFKTFontNameView.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // PDFKTFontNameView.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 "PDFKTFontNameView.h"
  11. @implementation PDFKTFontNameView
  12. {
  13. UITableView *_fontNamesTableView;
  14. }
  15. @synthesize fontNamedelegate = _fontNamedelegate;
  16. @synthesize fontNames = _fontNames;
  17. - (id)initWithFrame:(CGRect)frame
  18. {
  19. self = [super initWithFrame:frame];
  20. if (self) {
  21. _fontNamesTableView = [[UITableView alloc] initWithFrame:self.bounds];
  22. _fontNamesTableView.delegate = self;
  23. _fontNamesTableView.dataSource = self;
  24. _fontNamesTableView.separatorInset = UIEdgeInsetsZero;
  25. _fontNamesTableView.backgroundColor = [UIColor clearColor];
  26. _fontNamesTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
  27. [self addSubview:_fontNamesTableView];
  28. _fontNames = [[NSArray alloc] initWithObjects:@"Helvetica", @"Courier", @"Times-Roman",nil];
  29. }
  30. return self;
  31. }
  32. - (void)dealloc
  33. {
  34. _fontNamedelegate = nil;
  35. _fontNamesTableView.delegate = nil;
  36. _fontNamesTableView.dataSource = nil;
  37. [_fontNamesTableView release];
  38. [_fontNames release];
  39. [_fontName release];
  40. [super dealloc];
  41. }
  42. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  43. {
  44. self.fontName = self.fontNames[indexPath.row];
  45. [_fontNamesTableView reloadData];
  46. if ([_fontNamedelegate respondsToSelector:@selector(fontNamesView:didSelectedTextFontName:)]) {
  47. [_fontNamedelegate fontNamesView:self didSelectedTextFontName:[_fontNames objectAtIndex:indexPath.row]];
  48. }
  49. }
  50. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  51. return 1;
  52. }
  53. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  54. return [_fontNames count];
  55. }
  56. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  57. return 40;
  58. }
  59. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  60. {
  61. static NSString *CellIdentifier = @"FontNameCell";
  62. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  63. if (cell == nil) {
  64. cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
  65. }
  66. NSString *fontName = [_fontNames objectAtIndex:indexPath.row];;
  67. cell.textLabel.text = fontName;
  68. [cell.textLabel setFont:[UIFont fontWithName:fontName size:18]];
  69. cell.backgroundColor = [UIColor clearColor];
  70. if ([self.fontName isEqualToString:fontName]) {
  71. cell.accessoryType = UITableViewCellAccessoryCheckmark;
  72. } else {
  73. cell.accessoryType = UITableViewCellAccessoryNone;
  74. }
  75. cell.backgroundColor = [UIColor clearColor];
  76. return cell;
  77. }
  78. @end