// // CPDFBackgroundView.m // PDFViewer // // Created by kdanmobile_2 on 2023/1/2. // #define KBUTTON_WIDTH 28 #define KBUTTON_HEIGHT 28 #import "CPDFBackgroundView.h" #import "Masonry.h" @implementation CPDFBackgroundView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { _imageLabel = [[UILabel alloc] init]; [self addSubview:_imageLabel]; _selectBtn = [[UIButton alloc] init]; [self addSubview:_selectBtn]; _colorLabel = [[UILabel alloc] init]; [self addSubview:_colorLabel]; _colorArray = [NSMutableArray array]; for (NSInteger i = 0; i < 8; ++i) { _colorBtn = [UIButton buttonWithType:UIButtonTypeSystem]; [_colorArray addObject:_colorBtn]; [self addSubview:_colorBtn]; } } return self; } - (void)drawRect:(CGRect)rect { [super drawRect:rect]; _colorLabel.frame = CGRectMake(20, 5, 50, 30); _colorLabel.text = @"Color"; _imageLabel.frame = CGRectMake(20, 40, 140, 30); _imageLabel.text = @"Image"; for (NSInteger i = 0; i < _colorArray.count; i++) { [[[self colorArray][i] layer] setCornerRadius:KBUTTON_WIDTH / 2]; [[[self colorArray][i] layer] setMasksToBounds:YES]; [[_colorArray[i] layer] setBorderWidth:0.5f]; [[_colorArray[i] layer] setBorderColor:UIColor.systemGray4Color.CGColor]; } [_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 whiteColor]]; _selectBtn.layer.borderWidth = 1.0; _selectBtn.layer.borderColor = UIColor.systemGray4Color.CGColor; [_selectBtn setTitle:@"Select Image" forState:UIControlStateNormal]; [_selectBtn setTitleColor:UIColor.blackColor forState:UIControlStateNormal]; _selectBtn.layer.cornerRadius = 7; [self addConstraint]; } - (void)addConstraint { 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; } [_selectBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.mas_right).offset(-25); make.top.equalTo(self.colorLabel.mas_bottom).offset(5); make.width.mas_equalTo(180); make.height.equalTo(@35); }]; } @end