123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- //
- // 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
|