// // CPDFImageView.m // PDFViewer // // Created by kdan on 2022/11/16. // #import "PDFWatermarkImageView.h" #import "Masonry.h" @implementation PDFWatermarkImageView - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self createView]; [self assignData]; } return self; } #pragma mark - Layout - (void)layoutSubviews { [super layoutSubviews]; [self createFrame]; [self addConstraint]; } - (void)createView { _opacitySlider = [[UISlider alloc] init]; _imageScaleSlider = [[UISlider alloc] init]; _tileSwitch = [[UISwitch alloc] init]; _rangeLabel = [[UILabel alloc] init]; _tileLabel = [[UILabel alloc] init]; _sizeLabel = [[UILabel alloc] init]; _opacityLabel = [[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]; _imageLabel = [[UILabel alloc] init]; _selectBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; _pageBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [self addSubview:_opacitySlider]; [self addSubview:_sizeLabel]; [self addSubview:_opacityLabel]; [self addSubview:_imageScaleSlider]; [self addSubview:_tileSwitch]; [self addSubview:_rangeLabel]; [self addSubview:_tileLabel]; [self addSubview:_verticalLabel]; [self addSubview:_verticalField]; [self addSubview:_horizontalField]; [self addSubview:_horizontalLabel]; [self addSubview:_imageLabel]; [self addSubview:_selectBtn]; [self addSubview:_pageBtn]; [self setBackgroundColor:[UIColor whiteColor]]; } - (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); _sizeLabel.frame = CGRectMake(10, 80, 90, 30); _opacityLabel.frame = CGRectMake(10, 40, 90, 30); _imageLabel.frame = CGRectMake(10, 5, 150, 30); _selectBtn.layer.borderWidth = 1.0; _selectBtn.layer.borderColor = UIColor.grayColor.CGColor; [_selectBtn setTitle:@"Select Image" forState:UIControlStateNormal]; [_selectBtn setTitleColor:UIColor.blackColor forState:UIControlStateNormal]; _selectBtn.layer.cornerRadius = 7; _pageBtn.layer.borderWidth = 1.0; _pageBtn.layer.borderColor = UIColor.grayColor.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); }]; [_selectBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.mas_right).offset(-15); make.top.equalTo(self.mas_top).offset(2); make.left.equalTo(_horizontalField.mas_left); make.height.equalTo(@35); }]; [_imageScaleSlider mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.mas_right).offset(-15); make.left.equalTo(_sizeLabel.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); }]; [_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 = NSLocalizedString(@"Page Range", nil); _tileLabel.text = NSLocalizedString(@"Full Screen", nil); _sizeLabel.text = NSLocalizedString(@"Image Size", nil); _opacityLabel.text = NSLocalizedString(@"Opacity", nil); _verticalLabel.text = @"Y:"; _horizontalLabel.text = @"X:"; _imageLabel.text = NSLocalizedString(@"Image", nil); } @end