// // PDFSettingFontView.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 "PDFSettingFontView.h" @interface PDFSettingFontView () @property (nonatomic, assign) NSInteger minValue; @property (nonatomic, assign) NSInteger maxValue; @property (nonatomic, retain) UITableView *tableView; @end @implementation PDFSettingFontView - (id)initWithFrame:(CGRect)frame minValue:(NSInteger)minValue maxValue:(NSInteger)maxValue{ self = [super initWithFrame:frame]; self.minValue = minValue; self.maxValue = maxValue; if (self) { _tableView = [[UITableView alloc] initWithFrame:self.bounds]; _tableView.delegate = self; _tableView.dataSource = self; _tableView.separatorInset = UIEdgeInsetsZero; _tableView.backgroundColor = [UIColor clearColor]; _tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; [self addSubview:_tableView]; } return self; } - (void)dealloc { _fontNamedelegate = nil; _tableView.delegate = nil; _tableView.dataSource = nil; [_tableView release]; [super dealloc]; } - (void)setCurValue:(NSInteger)curValue { _curValue = curValue; [_tableView reloadData]; NSInteger row = self.curValue - self.minValue; NSIndexPath * indexPath = [NSIndexPath indexPathForRow:row inSection:0]; [_tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { self.curValue = _minValue + indexPath.row; if ([_fontNamedelegate respondsToSelector:@selector(fontNamesView:didSelectedTextFontName:)]) { [_fontNamedelegate fontNamesView:self didSelectedTextsize:(_minValue + indexPath.row)]; } } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return _maxValue - _minValue + 1; } - (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]; cell.backgroundColor = [UIColor clearColor]; } cell.textLabel.text = [NSString stringWithFormat:@"%@",@(_minValue + indexPath.row)]; if (self.curValue == _minValue + indexPath.row) { cell.accessoryType = UITableViewCellAccessoryCheckmark; } else { cell.accessoryType = UITableViewCellAccessoryNone; } cell.backgroundColor = [UIColor clearColor]; return cell; } @end