// // HeaderFooterAddView.m // PDFViewer // // Created by kdanmobile_2 on 2022/11/16. // #import "CPDFHeaderFooterAddView.h" @implementation CPDFHeaderFooterAddView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; CGFloat height = self.bounds.size.height / 15 - 35; CGFloat width = self.bounds.size.width / 4 - 10; CGFloat offsetx = 3.5; if (self) { //Page number location _localLabel = [[UILabel alloc] initWithFrame:CGRectMake(offsetx, offsetx, width * 2, height)]; [_localLabel setText:@"Page number position"]; _localLabel.font = [UIFont boldSystemFontOfSize:12]; NSArray *arraySegmmentL = [NSArray arrayWithObjects:@"Header",@"Footer", nil]; _localSegment = [[UISegmentedControl alloc] initWithItems:arraySegmmentL]; _localSegment.frame = CGRectMake(4 * offsetx, height + 2 * offsetx, self.bounds.size.width - 8 * offsetx, height * 2); [self addSubview:_localLabel]; [self addSubview:_localSegment]; //alignment _alignmentLabel = [[UILabel alloc] initWithFrame:CGRectMake(3.5, 3 * height + 3 * offsetx, width, height)]; [_alignmentLabel setText:@"alignment"]; _alignmentLabel.font = [UIFont boldSystemFontOfSize:12]; NSArray *arraySegmmentA = [NSArray arrayWithObjects:@"Left",@"Center",@"Right", nil]; _aligbmentSegment = [[UISegmentedControl alloc] initWithItems:arraySegmmentA]; _aligbmentSegment.frame = CGRectMake(4 * offsetx, 4 * height + 4 * offsetx, self.bounds.size.width - 8 * offsetx, height * 2); [self addSubview:_alignmentLabel]; [self addSubview:_aligbmentSegment]; //font color _colorLabel = [[UILabel alloc] initWithFrame:CGRectMake(3.5, 6 * height + 5 * offsetx, width, height)]; [_colorLabel setText:@"Font Color"]; _colorLabel.font = [UIFont boldSystemFontOfSize:12]; _colerImage = [[UIImageView alloc] initWithFrame:CGRectMake(4 * offsetx,7 * height + 6 * offsetx , self.bounds.size.width, 2*height)]; _colerImage.image = [UIImage imageNamed:@"text_color_bar"]; _colorSlider = [[UISlider alloc] initWithFrame:CGRectMake(4 * offsetx,9 * height + 7 * offsetx , self.bounds.size.width - 8 * offsetx, 2 * height)]; _colorSlider.minimumValue = 0; _colorSlider.maximumValue = 90; _colorSlider.value = 5; [self addSubview:_colorLabel]; [self addSubview:_colorSlider]; [self addSubview:_colerImage]; //page number _pageNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(3.5, 11 * height + 8 * offsetx, width + offsetx, height * 2)]; [_pageNumberLabel setText:@"Page Text"]; _pageNumberLabel.font = [UIFont boldSystemFontOfSize:14]; NSArray *str = [[NSArray alloc] initWithObjects:@"1",@"第1页", nil]; _dropdownView = [[CPDFDropDownView alloc] initWithFrame:CGRectMake(2 * offsetx + width, 11 * height + 8 * offsetx, width - offsetx, height * 2) WithString:str]; [self addSubview:_dropdownView]; [self addSubview:_pageNumberLabel]; //font size _fontSizeLabel = [[UILabel alloc] initWithFrame:CGRectMake(3 * offsetx + width * 2, 11 * height + 8 * offsetx, width, height * 2)]; [_fontSizeLabel setText:@"Font Szie"]; _fontSizeLabel.font = [UIFont boldSystemFontOfSize:14]; _fontSizeText = [[UITextField alloc] initWithFrame:CGRectMake(2 * offsetx + 3 * width, 11 * height + 8 * offsetx, width, height * 2)]; _fontSizeText.borderStyle = UITextBorderStyleRoundedRect; [self addSubview:_fontSizeLabel]; [self addSubview:_fontSizeText]; //font index _pageIndexLabel = [[UILabel alloc] initWithFrame:CGRectMake(offsetx, 13 * height + 9 * offsetx, width, height * 2)]; [_pageIndexLabel setText:@"Page Star"]; _pageIndexLabel.font = [UIFont boldSystemFontOfSize:14]; _pageIndexNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(offsetx + width, 13 * height + 10 * offsetx, width, height * 2)]; _pageIndexNumberLabel.backgroundColor = [UIColor whiteColor]; _pageIndexNumberLabel.textColor = [UIColor blackColor]; _pageIndexNumberLabel.textAlignment = NSTextAlignmentCenter; _pageIndexNumberStepper = [[UIStepper alloc] initWithFrame:CGRectMake(offsetx + width * 2, 13 * height + 11 * offsetx, width, height * 2)]; // The step value is updated in real time as the user interacts _pageIndexNumberStepper.continuous = YES; // default = YES // The user continues to press and hold, automatically increasing or decreasing _pageIndexNumberStepper.autorepeat = YES; // default = YES // If set to YES, the value loops between min <-> max _pageIndexNumberStepper.wraps = NO; // default = NO _pageIndexNumberStepper.minimumValue = 1; // default 0 _pageIndexNumberStepper.maximumValue = 100; // default 100 _pageIndexNumberStepper.stepValue = 1; // default 1 _pageIndexNumberStepper.value = 1; // 设置 Target-Action [_pageIndexNumberStepper addTarget:self action:@selector(stepperValueChanged:) forControlEvents:UIControlEventValueChanged]; [self addSubview:_pageIndexLabel]; [self addSubview:_pageIndexNumberLabel]; [self addSubview:_pageIndexNumberStepper]; self.backgroundColor = [UIColor whiteColor]; } return self; } - (void)stepperValueChanged:(UIStepper *)pageIndexNumberStepper { int pageIndex = (int)pageIndexNumberStepper.value; NSString *value = [NSString stringWithFormat:@"%d",pageIndex]; self.pageIndexLabel.font = [UIFont boldSystemFontOfSize:12.0]; self.pageIndexNumberLabel.text = value; } @end