// // BatesAddView.m // PDFViewer // // Created by kdanmobile_2 on 2022/11/18. // #import "PDFBatesAddView.h" #import "Masonry.h" @implementation PDFBatesAddView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Font index _pageIndexLabel = [[UILabel alloc] init]; _pageIndexNumberText = [[UITextField alloc] init]; [self addSubview:_pageIndexLabel]; [self addSubview:_pageIndexNumberText]; // Font Name _fontNameLabel = [[UILabel alloc] init]; _fontNameText = [[UITextField alloc] init]; [self addSubview:_fontNameLabel]; [self addSubview:_fontNameText]; // Page number _pageNumberLabel = [[UILabel alloc] init]; _pageNumberText = [[UITextField alloc] init]; [self addSubview:_pageNumberLabel]; [self addSubview:_pageNumberText]; self.backgroundColor = [UIColor whiteColor]; } return self; } #pragma mark - Layout - (void)layoutSubviews { [super layoutSubviews]; CGFloat offsetx = 3.5; // Font index [_pageIndexLabel 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); }]; [_pageIndexNumberText mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.colorSlider.mas_bottom).offset(offsetx); make.left.equalTo(_pageIndexLabel.mas_right).offset(offsetx); make.height.mas_equalTo(34); make.width.mas_equalTo(93); }]; // Font Name [_fontNameLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.colorSlider.mas_bottom).offset(offsetx); make.left.equalTo(_pageIndexNumberText.mas_right).offset(offsetx + 20); make.height.mas_equalTo(34); make.width.mas_equalTo(73); }]; [_fontNameText mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.colorSlider.mas_bottom).offset(offsetx); make.left.equalTo(_fontNameLabel.mas_right).offset(offsetx); make.height.mas_equalTo(34); make.width.mas_equalTo(93); }]; // Page number [_pageNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(_pageIndexLabel.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(_pageIndexNumberText.mas_bottom).offset(offsetx+5); make.left.equalTo(_pageNumberLabel.mas_right).offset(offsetx); make.height.mas_equalTo(33); make.width.mas_equalTo(153); }]; } #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; // Font index [_pageIndexLabel setText:NSLocalizedString(@"Start Page", nil)]; _pageIndexLabel.font = [UIFont boldSystemFontOfSize:12]; _pageIndexNumberText.delegate = self; _pageIndexNumberText.borderStyle = UITextBorderStyleRoundedRect; _pageIndexNumberText.placeholder = @"1"; // Font Name [_fontNameLabel setText:NSLocalizedString(@"Font Name", nil)]; _fontNameLabel.font = [UIFont boldSystemFontOfSize:12]; _fontNameText.inputView = [[UIView alloc] initWithFrame:CGRectZero]; _fontNameText.inputAccessoryView = [[UIView alloc] initWithFrame:CGRectZero]; _fontNameText.adjustsFontSizeToFitWidth = YES; _fontNameText.minimumFontSize = 6; _fontNameText.borderStyle = UITextBorderStyleRoundedRect; _fontNameText.tintColor = [UIColor clearColor]; _fontNameText.placeholder = @"Helvetica"; _fontNameText.keyboardType = UIKeyboardTypeDefault; _fontNameText.delegate = self; // Page number [_pageNumberLabel setText:NSLocalizedString(@"Page Text", nil)]; _pageNumberLabel.font = [UIFont boldSystemFontOfSize:14]; _pageNumberText.delegate = self; _pageNumberText.borderStyle = UITextBorderStyleRoundedRect; _pageNumberText.placeholder = @"#2#1#0#0"; } #pragma mark - UITextFieldDelegate - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES; } - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if (_pageIndexNumberText == 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