// // HeaderFooterAddView.m // PDFViewer // // Created by kdanmobile_2 on 2022/11/16. // #import "PDFHeaderFooterAddView.h" //#import "Masonry.h" @implementation PDFHeaderFooterAddView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // // Page number // _pageNumberLabel = [[UILabel alloc] init]; // _pageNumberText = [[UITextField alloc] init]; // // [self addSubview:_pageNumberLabel]; // [self addSubview:_pageNumberText]; // // // Font size // _fontSizeLabel = [[UILabel alloc] init]; // _fontSizeText = [[UITextField alloc] init]; // // [self addSubview:_fontSizeLabel]; // [self addSubview:_fontSizeText]; // // // Page index // _pageIndexLabel = [[UILabel alloc] init]; // _pageIndexNumberText = [[UITextField alloc] init]; // // [self addSubview:_pageIndexLabel]; // [self addSubview:_pageIndexNumberText]; // // self.backgroundColor = [UIColor whiteColor]; // self = [[NSBundle mainBundle] loadNibNamed:@"HeaderFooterAddView" owner:nil options:nil].firstObject; _pageIndexNumberText.delegate = self; _fontSizeText.delegate = self; _pageNumberText.inputView = [[UIView alloc] initWithFrame:CGRectZero]; _pageNumberText.inputAccessoryView = [[UIView alloc] initWithFrame:CGRectZero]; } return self; } //#pragma mark - Layout // //- (void)layoutSubviews { // [super layoutSubviews]; // CGFloat offsetx = 3.5; // // // Page number // [_pageNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.equalTo(self.colorSlider.mas_bottom).offset(offsetx); // make.left.equalTo(self.mas_left).offset(offsetx); // make.height.mas_equalTo(34); // make.width.mas_equalTo(73); // }]; // // [_pageNumberText mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.equalTo(self.colorSlider.mas_bottom).offset(offsetx); // make.left.equalTo(_pageNumberLabel.mas_right).offset(offsetx); // make.height.mas_equalTo(34); // make.width.mas_equalTo(93); // }]; // // // Font size // [_fontSizeLabel mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.equalTo(self.colorSlider.mas_bottom).offset(offsetx); // make.left.equalTo(_pageNumberText.mas_right).offset(offsetx + 20); // make.height.mas_equalTo(34); // make.width.mas_equalTo(73); // }]; // // [_fontSizeText mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.equalTo(self.colorSlider.mas_bottom).offset(offsetx); // make.left.equalTo(_fontSizeLabel.mas_right).offset(offsetx); // make.height.mas_equalTo(34); // make.width.mas_equalTo(93); // }]; // // // Page index // [_pageIndexLabel mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.equalTo(_pageNumberLabel.mas_bottom).offset(offsetx); // make.left.equalTo(self.mas_left).offset(offsetx); // make.height.mas_equalTo(34); // make.width.mas_equalTo(73); // }]; // // [_pageIndexNumberText mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.equalTo(_pageNumberText.mas_bottom).offset(offsetx+5); // make.left.equalTo(_pageIndexLabel.mas_right).offset(offsetx); // make.height.mas_equalTo(33); // make.width.mas_equalTo(93); // }]; //} // //#pragma mark - Assignment // //- (void)setText { // // Page number location // [self.localLabel setText:NSLocalizedString(@"Page number position", nil)]; // self.localLabel.font = [UIFont boldSystemFontOfSize:12]; // // // Alignment // [self.alignmentLabel setText:NSLocalizedString(@"alignment", nil)]; // self.alignmentLabel.font = [UIFont boldSystemFontOfSize:12]; // // // Font color // [self.colorLabel setText:NSLocalizedString(@"Font Color", nil)]; // self.colorLabel.font = [UIFont boldSystemFontOfSize:12]; // // CALayer *layer = [self.colerImage layer]; // layer.borderColor = [[UIColor blackColor] CGColor]; // layer.borderWidth = 0.5f; // self.colerImage.image = [UIImage imageNamed:@"text_color_bar"]; // // self.colorSlider.minimumValue = 0; // self.colorSlider.maximumValue = 100; // self.colorSlider.value = 5; // // // Page number // [_pageNumberLabel setText:NSLocalizedString(@"Page Text", nil)]; // _pageNumberLabel.font = [UIFont boldSystemFontOfSize:14]; // // _pageNumberText.inputView = [[UIView alloc] initWithFrame:CGRectZero]; // _pageNumberText.inputAccessoryView = [[UIView alloc] initWithFrame:CGRectZero]; // _pageNumberText.delegate = self; // _pageNumberText.adjustsFontSizeToFitWidth = YES; // _pageNumberText.tintColor = [UIColor clearColor]; // _pageNumberText.borderStyle = UITextBorderStyleRoundedRect; // _pageNumberText.placeholder = @"text"; // // // Font size // [_fontSizeLabel setText:NSLocalizedString(@"Font Szie", nil)]; // _fontSizeLabel.font = [UIFont boldSystemFontOfSize:14]; // // _fontSizeText.keyboardType = UIKeyboardTypeNumbersAndPunctuation; // _fontSizeText.clearsOnBeginEditing = YES; // _fontSizeText.borderStyle = UITextBorderStyleRoundedRect; // _fontSizeText.placeholder = @"18.0"; // _fontSizeText.delegate = self; // _fontSizeText.keyboardType = UIKeyboardTypeDefault; // // // Page index // [_pageIndexLabel setText:NSLocalizedString(@"Page Start", nil)]; // _pageIndexLabel.font = [UIFont boldSystemFontOfSize:12]; // // _pageIndexNumberText.keyboardType = UIKeyboardTypeNumbersAndPunctuation; // _pageIndexNumberText.clearsOnBeginEditing = YES; // _pageIndexNumberText.delegate = self; // _pageIndexNumberText.borderStyle = UITextBorderStyleRoundedRect; // _pageIndexNumberText.placeholder = @"1"; //} #pragma mark - UITextFieldDelegate - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES; } - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if (_fontSizeText == textField || _pageNumberText == textField) { return [self validateValue:string]; } return YES; } - (BOOL)validateValue:(NSString *)number { BOOL res = YES; NSCharacterSet *numberSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"]; NSInteger i = 0; while (i < number.length) { NSString *str = [number substringWithRange:NSMakeRange(i, 1)]; NSRange range = [str rangeOfCharacterFromSet:numberSet]; if (range.length == 0) { res = NO; break; } i++; } return res; } @end