CPDFBackgroundView.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // CPDFBackgroundView.m
  3. // PDFViewer
  4. //
  5. // Created by kdanmobile_2 on 2023/1/2.
  6. //
  7. #define KBUTTON_WIDTH 28
  8. #define KBUTTON_HEIGHT 28
  9. #import "CPDFBackgroundView.h"
  10. #import "Masonry.h"
  11. @implementation CPDFBackgroundView
  12. - (instancetype)initWithFrame:(CGRect)frame {
  13. self = [super initWithFrame:frame];
  14. if (self) {
  15. _imageLabel = [[UILabel alloc] init];
  16. [self addSubview:_imageLabel];
  17. _selectBtn = [[UIButton alloc] init];
  18. [self addSubview:_selectBtn];
  19. _colorLabel = [[UILabel alloc] init];
  20. [self addSubview:_colorLabel];
  21. _colorArray = [NSMutableArray array];
  22. for (NSInteger i = 0; i < 8; ++i) {
  23. _colorBtn = [UIButton buttonWithType:UIButtonTypeSystem];
  24. [_colorArray addObject:_colorBtn];
  25. [self addSubview:_colorBtn];
  26. }
  27. }
  28. return self;
  29. }
  30. - (void)drawRect:(CGRect)rect {
  31. [super drawRect:rect];
  32. _colorLabel.frame = CGRectMake(20, 5, 50, 30);
  33. _colorLabel.text = @"Color";
  34. _imageLabel.frame = CGRectMake(20, 40, 140, 30);
  35. _imageLabel.text = @"Image";
  36. for (NSInteger i = 0; i < _colorArray.count; i++) {
  37. [[[self colorArray][i] layer] setCornerRadius:KBUTTON_WIDTH / 2];
  38. [[[self colorArray][i] layer] setMasksToBounds:YES];
  39. [[_colorArray[i] layer] setBorderWidth:0.5f];
  40. [[_colorArray[i] layer] setBorderColor:UIColor.systemGray4Color.CGColor];
  41. }
  42. [_colorArray[0] setBackgroundColor:[UIColor redColor]];
  43. [_colorArray[1] setBackgroundColor:[UIColor orangeColor]];
  44. [_colorArray[2] setBackgroundColor:[UIColor yellowColor]];
  45. [_colorArray[3] setBackgroundColor:[UIColor greenColor]];
  46. [_colorArray[4] setBackgroundColor:[UIColor blueColor]];
  47. [_colorArray[5] setBackgroundColor:[UIColor brownColor]];
  48. [_colorArray[6] setBackgroundColor:[UIColor purpleColor]];
  49. [_colorArray[7] setBackgroundColor:[UIColor whiteColor]];
  50. _selectBtn.layer.borderWidth = 1.0;
  51. _selectBtn.layer.borderColor = UIColor.systemGray4Color.CGColor;
  52. [_selectBtn setTitle:@"Select Image" forState:UIControlStateNormal];
  53. [_selectBtn setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
  54. _selectBtn.layer.cornerRadius = 7;
  55. [self addConstraint];
  56. }
  57. - (void)addConstraint {
  58. NSInteger offset = 10;
  59. for (NSInteger i = 0; i < _colorArray.count; ++i) {
  60. [_colorArray[i] mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.right.equalTo(self.mas_right).offset( - offset);
  62. make.top.equalTo(self.mas_top).offset(5);
  63. make.width.equalTo(@KBUTTON_WIDTH);
  64. make.height.equalTo(@KBUTTON_HEIGHT);
  65. }];
  66. offset += 40;
  67. }
  68. [_selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.right.equalTo(self.mas_right).offset(-25);
  70. make.top.equalTo(self.colorLabel.mas_bottom).offset(5);
  71. make.width.mas_equalTo(180);
  72. make.height.equalTo(@35);
  73. }];
  74. }
  75. @end