// // PDFKTFontNameView.m // PDFReader // // Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved. // // The PDF Reader Sample applications are licensed with a modified BSD license. // Please see License for details. This notice may not be removed from this file. // #import "PDFKTFontNameView.h" @implementation PDFKTFontNameView { UITableView *_fontNamesTableView; } @synthesize fontNamedelegate = _fontNamedelegate; @synthesize fontNames = _fontNames; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { _fontNamesTableView = [[UITableView alloc] initWithFrame:self.bounds]; _fontNamesTableView.delegate = self; _fontNamesTableView.dataSource = self; _fontNamesTableView.separatorInset = UIEdgeInsetsZero; _fontNamesTableView.backgroundColor = [UIColor clearColor]; _fontNamesTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; [self addSubview:_fontNamesTableView]; _fontNames = [[NSArray alloc] initWithObjects:@"Helvetica", @"Courier", @"Times-Roman",nil]; } return self; } - (void)dealloc { _fontNamedelegate = nil; _fontNamesTableView.delegate = nil; _fontNamesTableView.dataSource = nil; [_fontNamesTableView release]; [_fontNames release]; [_fontName release]; [super dealloc]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { self.fontName = self.fontNames[indexPath.row]; [_fontNamesTableView reloadData]; if ([_fontNamedelegate respondsToSelector:@selector(fontNamesView:didSelectedTextFontName:)]) { [_fontNamedelegate fontNamesView:self didSelectedTextFontName:[_fontNames objectAtIndex:indexPath.row]]; } } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [_fontNames count]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 40; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"FontNameCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } NSString *fontName = [_fontNames objectAtIndex:indexPath.row];; cell.textLabel.text = fontName; [cell.textLabel setFont:[UIFont fontWithName:fontName size:18]]; cell.backgroundColor = [UIColor clearColor]; if ([self.fontName isEqualToString:fontName]) { cell.accessoryType = UITableViewCellAccessoryCheckmark; } else { cell.accessoryType = UITableViewCellAccessoryNone; } cell.backgroundColor = [UIColor clearColor]; return cell; } @end