TiUIDefaultButtonView.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // TiUIDefaultButtonView.m
  3. // TiSDKDemo
  4. //
  5. // Created by iMacA1002 on 2019/12/2.
  6. // Copyright © 2020 Tillusory Tech. All rights reserved.
  7. //
  8. #import "TiUIDefaultButtonView.h"
  9. #import "TIConfig.h"
  10. @interface TiUIDefaultButtonView ()
  11. @property(nonatomic, strong) UIButton *mainSwitchButton;
  12. //@property(nonatomic, strong) UIButton *cameraCaptureButton;
  13. //@property(nonatomic, strong) UIButton *switchCameraButton;
  14. @end
  15. @implementation TiUIDefaultButtonView
  16. // MARK: --懒加载--
  17. -(UIButton *)mainSwitchButton{
  18. if (_mainSwitchButton==nil){
  19. _mainSwitchButton = [[UIButton alloc] init];
  20. [_mainSwitchButton setTag:0];
  21. [_mainSwitchButton setImage:[UIImage imageNamed:@"btn_meiyan"] forState:UIControlStateNormal];
  22. [_mainSwitchButton addTarget:self action:@selector(onButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  23. }
  24. return _mainSwitchButton;
  25. }
  26. //-(UIButton *)cameraCaptureButton{
  27. // if (_cameraCaptureButton==nil) {
  28. // _cameraCaptureButton = [[UIButton alloc] init];
  29. // [_cameraCaptureButton setTag:1];
  30. // [_cameraCaptureButton setImage:[UIImage imageNamed:@"btn_take photo"] forState:UIControlStateNormal];
  31. // [_cameraCaptureButton setImage:[UIImage imageNamed:@"btn_take photo"] forState:UIControlStateSelected];
  32. // [_cameraCaptureButton addTarget:self action:@selector(onButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  33. // }
  34. // return _cameraCaptureButton;
  35. //}
  36. //-(UIButton *)switchCameraButton{
  37. // if (_switchCameraButton==nil) {
  38. // _switchCameraButton = [[UIButton alloc] init];
  39. // [_switchCameraButton setTag:2];
  40. // [_switchCameraButton setImage:[UIImage imageNamed:@"btn_shexiangtou"] forState:UIControlStateNormal];
  41. // [_switchCameraButton addTarget:self action:@selector(onButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  42. // }
  43. // return _switchCameraButton;
  44. //}
  45. - (instancetype)init
  46. {
  47. self = [super init];
  48. if (self) {
  49. [self initView];
  50. }
  51. return self;
  52. }
  53. - (instancetype)initWithFrame:(CGRect)frame
  54. {
  55. self = [super initWithFrame:frame];
  56. if (self) {
  57. [self initView];
  58. }
  59. return self;
  60. }
  61. - (instancetype)initWithCoder:(NSCoder *)coder
  62. {
  63. self = [super initWithCoder:coder];
  64. if (self) {
  65. [self initView];
  66. }
  67. return self;
  68. }
  69. -(void)initView{
  70. [self addSubview:self.mainSwitchButton];
  71. // [self addSubview:self.cameraCaptureButton];
  72. // [self addSubview:self.switchCameraButton];
  73. [self.mainSwitchButton mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.left.equalTo(self.mas_left).offset(DefaultButton_WIDTH/2.5);
  75. make.top.equalTo(self.mas_centerY);
  76. make.width.height.mas_equalTo(DefaultButton_WIDTH-DefaultButton_WIDTH/2);
  77. }];
  78. // [self.cameraCaptureButton mas_makeConstraints:^(MASConstraintMaker *make) {
  79. // make.centerX.equalTo(self.mas_centerX);
  80. // make.top.equalTo(self.mas_centerY);
  81. // make.width.height.mas_equalTo(DefaultButton_WIDTH);
  82. // }];
  83. // [self.switchCameraButton mas_makeConstraints:^(MASConstraintMaker *make) {
  84. // make.right.equalTo(self.mas_right).offset(-DefaultButton_WIDTH/2.5);
  85. // make.top.equalTo(self.mas_centerY);
  86. // make.width.height.mas_equalTo(DefaultButton_WIDTH-DefaultButton_WIDTH/2);
  87. // }];
  88. }
  89. -(void)onButtonClick:(UIButton *)button{
  90. if (self.onClickBlock) {
  91. self.onClickBlock(button.tag);
  92. }
  93. }
  94. - (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
  95. UIView *hitView = [super hitTest:point withEvent:event];
  96. if(hitView == self){
  97. return nil;
  98. }
  99. return hitView;
  100. }
  101. @end