// // CPDFTextView.m // PDFViewer // // Created by kdan on 2022/11/16. // #import "CPDFTextView.h" #import "Masonry.h" #define KBUTTON_WIDTH 28 #define KBUTTON_HEIGHT 28 @implementation CPDFTextView - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self createView]; [self assignData]; self.backgroundColor = [UIColor whiteColor]; } return self; } #pragma mark - Layout - (void)layoutSubviews { [super layoutSubviews]; [self createFrame]; [self addConstraint]; } - (void)createView { _opacitySlider = [[UISlider alloc] init]; _textScaleSlider = [[UISlider alloc] init]; _tileSwitch = [[UISwitch alloc] init]; _rangeLabel = [[UILabel alloc] init]; _tileLabel = [[UILabel alloc] init]; _textLabel = [[UILabel alloc] init]; _opacityLabel = [[UILabel alloc] init]; _colorLabel = [[UILabel alloc] init]; _verticalField = [[UITextField alloc] init]; _verticalField.borderStyle = UITextBorderStyleRoundedRect; _verticalLabel = [[UILabel alloc] init]; _horizontalField = [[UITextField alloc] init]; _horizontalField.borderStyle = UITextBorderStyleRoundedRect; _horizontalLabel = [[UILabel alloc] init]; _pageBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; _colorArray = [NSMutableArray array]; for (NSInteger i = 0; i < 8; ++i) { _colorBtn = [UIButton buttonWithType:UIButtonTypeSystem]; [_colorArray addObject:_colorBtn]; [self addSubview:_colorBtn]; } [self addSubview:_opacitySlider]; [self addSubview:_textLabel]; [self addSubview:_opacityLabel]; [self addSubview:_textScaleSlider]; [self addSubview:_tileSwitch]; [self addSubview:_rangeLabel]; [self addSubview:_tileLabel]; [self addSubview:_verticalLabel]; [self addSubview:_verticalField]; [self addSubview:_horizontalField]; [self addSubview:_horizontalLabel]; [self addSubview:_colorLabel]; [self addSubview:_pageBtn]; } - (void)createFrame { // y -- 40 height -- 30 _tileSwitch.frame = CGRectMake(100, 160, 10, 10); _rangeLabel.frame = CGRectMake(10, 120, 180, 30); _tileLabel.frame = CGRectMake(10, 160, 100, 30); _textLabel.frame = CGRectMake(10, 80, 90, 30); _opacityLabel.frame = CGRectMake(10, 40, 90, 30); _colorLabel.frame = CGRectMake(10, 5, 50, 30); for (NSInteger i = 0; i < _colorArray.count; i++) { [[[self colorArray][i] layer] setCornerRadius:KBUTTON_WIDTH / 2]; [[[self colorArray][i] layer] setMasksToBounds:YES]; } [_colorArray[0] setBackgroundColor:[UIColor redColor]]; [_colorArray[1] setBackgroundColor:[UIColor orangeColor]]; [_colorArray[2] setBackgroundColor:[UIColor yellowColor]]; [_colorArray[3] setBackgroundColor:[UIColor greenColor]]; [_colorArray[4] setBackgroundColor:[UIColor blueColor]]; [_colorArray[5] setBackgroundColor:[UIColor brownColor]]; [_colorArray[6] setBackgroundColor:[UIColor purpleColor]]; [_colorArray[7] setBackgroundColor:[UIColor grayColor]]; _pageBtn.layer.borderWidth = 1.0; _pageBtn.layer.borderColor = UIColor.systemGray4Color.CGColor; [_pageBtn setTitle:@"Page Range" forState:UIControlStateNormal]; [_pageBtn setTitleColor:UIColor.blackColor forState:UIControlStateNormal]; _pageBtn.layer.cornerRadius = 7; } - (void)addConstraint { [_verticalField mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.mas_right).offset(-15); make.top.equalTo(self.pageBtn.mas_bottom).offset(10); make.width.equalTo(@80); make.height.equalTo(@30); }]; [_verticalLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.mas_right).offset(-95); make.top.equalTo(self.pageBtn.mas_bottom).offset(10); make.width.equalTo(@20); make.height.equalTo(@30); }]; [_horizontalField mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.mas_right).offset(-115); make.top.equalTo(self.pageBtn.mas_bottom).offset(10); make.width.equalTo(@80); make.height.equalTo(@30); }]; [_horizontalLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.mas_right).offset(-195); make.top.equalTo(self.pageBtn.mas_bottom).offset(10); make.width.equalTo(@20); make.height.equalTo(@30); }]; [_textScaleSlider mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.mas_right).offset(-15); make.left.equalTo(_textLabel.mas_right).offset(0); make.top.equalTo(self.mas_top).offset(80); make.height.equalTo(@30); }]; [_opacitySlider mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.mas_right).offset(-15); make.left.equalTo(_opacityLabel.mas_right).offset(0); make.top.equalTo(self.mas_top).offset(40); make.height.equalTo(@30); }]; NSInteger offset = 10; for (NSInteger i = 0; i < _colorArray.count; ++i) { [_colorArray[i] mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.mas_right).offset( - offset); make.top.equalTo(self.mas_top).offset(5); make.width.equalTo(@KBUTTON_WIDTH); make.height.equalTo(@KBUTTON_HEIGHT); }]; offset += 40; } [_pageBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.mas_right).offset(-15); make.top.equalTo(self.mas_top).offset(115); make.left.equalTo(_horizontalField.mas_left); make.height.equalTo(@35); }]; } - (void)assignData { _rangeLabel.text = @"Page Range"; _tileLabel.text = @"Full Screen"; _textLabel.text = @"Font Size"; _opacityLabel.text = @"Opacity"; _verticalLabel.text = @"Y:"; _horizontalLabel.text = @"X:"; _colorLabel.text = @"Color"; } @end