财神随手记账

AlertWith2ButtonView.m 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //
  2. // AlertWith2ButtonView.m
  3. // FoolsparadiseView
  4. //
  5. // Created by foolsparadise on 19/9/2017.
  6. // Copyright © 2017 github.com/foolsparadise All rights reserved.
  7. //
  8. #import "AlertWith2ButtonView.h"
  9. @interface AlertWith2ButtonView ()
  10. @property (nonatomic, strong) UIButton *alertButton;
  11. @property (nonatomic, strong) UIButton *leftButton;
  12. @property (nonatomic, strong) UIButton *rightButton;
  13. @end
  14. @implementation AlertWith2ButtonView
  15. /*
  16. // Only override drawRect: if you perform custom drawing.
  17. // An empty implementation adversely affects performance during animation.
  18. - (void)drawRect:(CGRect)rect {
  19. // Drawing code
  20. }
  21. */
  22. - (instancetype)initWithFrame:(CGRect)frame
  23. {
  24. self = [super initWithFrame:frame];
  25. if (self) {
  26. [self setupUI];
  27. }
  28. return self;
  29. }
  30. - (void)setupUI {
  31. self.layer.masksToBounds = YES;
  32. self.layer.cornerRadius = 0;
  33. self.layer.borderWidth = 1;
  34. self.backgroundColor = [UIColor whiteColor];
  35. [self addSubview:self.alertButton];
  36. [self.alertButton mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.top.mas_equalTo(self.mas_top).mas_offset(35);
  38. //make.left.mas_equalTo(self.left).mas_offset(0);
  39. make.size.mas_equalTo(CGSizeMake(self.width, 14.5));
  40. make.centerX.mas_equalTo(self.mas_centerX).mas_offset(0);
  41. }];
  42. [self addSubview:self.leftButton];
  43. [self.leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.top.mas_equalTo(self.mas_top).mas_offset(69);
  45. //make.left.mas_equalTo(self.left).mas_offset(0);
  46. make.size.mas_equalTo(CGSizeMake(self.width*0.5-40, 44));
  47. make.right.mas_equalTo(self.mas_centerX).mas_offset(-20);
  48. }];
  49. [self addSubview:self.rightButton];
  50. [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.top.mas_equalTo(self.mas_top).mas_offset(69);
  52. //make.left.mas_equalTo(self.left).mas_offset(0);
  53. make.size.mas_equalTo(CGSizeMake(self.width*0.5-40, 44));
  54. make.left.mas_equalTo(self.mas_centerX).mas_offset(20);
  55. }];
  56. }
  57. - (void)setTitleAlertString:(NSString *)titleAlertString
  58. {
  59. [self.alertButton setTitle:NSLocalizedStringFromTable(titleAlertString, @"InfoPlist", nil) forState:UIControlStateNormal];
  60. self.alertButton.titleLabel.font = [UIFont systemFontOfSize:15];
  61. [self.alertButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  62. }
  63. - (void)setLeftButtonString:(NSString *)leftButtonString
  64. {
  65. [self.leftButton setTitle:NSLocalizedStringFromTable(leftButtonString, @"InfoPlist", nil) forState:UIControlStateNormal];
  66. self.leftButton.titleLabel.font = [UIFont systemFontOfSize:16];
  67. [self.leftButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  68. }
  69. - (void)setRightButtonString:(NSString *)rightButtonString
  70. {
  71. [self.rightButton setTitle:NSLocalizedStringFromTable(rightButtonString, @"InfoPlist", nil) forState:UIControlStateNormal];
  72. self.rightButton.titleLabel.font = [UIFont systemFontOfSize:16];
  73. [self.rightButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  74. }
  75. - (UIButton *)alertButton
  76. {
  77. if (!_alertButton) {
  78. _alertButton = [UIButton buttonWithType:UIButtonTypeCustom];
  79. _alertButton.backgroundColor = [UIColor clearColor];
  80. //[_alertButton setTitle:@"SomeTitle" forState:UIControlStateNormal];
  81. //_alertButton.titleLabel.font = [UIFont systemFontOfSize:14];
  82. //[_alertButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  83. //_alertButton.layer.borderColor = RGBCOLOR(226, 226, 226).CGColor;
  84. //_alertButton.layer.borderWidth = 1;
  85. _alertButton.layer.borderColor = [UIColor whiteColor].CGColor;
  86. _alertButton.layer.borderWidth = 0;
  87. [_alertButton.layer setMasksToBounds:YES];
  88. [_alertButton.layer setCornerRadius:12.0];
  89. _alertButton.tag = 0; //为零,就不响应了
  90. [_alertButton addTarget:self action:@selector(click_Button:) forControlEvents:UIControlEventTouchUpInside];
  91. }
  92. return _alertButton;
  93. }
  94. - (UIButton *)leftButton
  95. {
  96. if (!_leftButton) {
  97. _leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
  98. _leftButton.backgroundColor = [UIColor whiteColor];
  99. //[_leftButton setTitle:@"SomeTitle" forState:UIControlStateNormal];
  100. //_leftButton.titleLabel.font = [UIFont systemFontOfSize:14];
  101. //[_leftButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  102. _leftButton.layer.borderWidth = 1;
  103. _leftButton.layer.borderColor = [UIColor whiteColor].CGColor;
  104. _leftButton.layer.borderWidth = 0;
  105. [_leftButton.layer setMasksToBounds:YES];
  106. [_leftButton.layer setCornerRadius:12.0];
  107. _leftButton.tag = 1; //为零,就不响应了
  108. [_leftButton addTarget:self action:@selector(click_Button:) forControlEvents:UIControlEventTouchUpInside];
  109. }
  110. return _leftButton;
  111. }
  112. - (UIButton *)rightButton
  113. {
  114. if (!_rightButton) {
  115. _rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
  116. _rightButton.backgroundColor = [UIColor whiteColor];
  117. //[_rightButton setTitle:@"SomeTitle" forState:UIControlStateNormal];
  118. //_rightButton.titleLabel.font = [UIFont systemFontOfSize:14];
  119. //[_rightButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  120. _rightButton.layer.borderWidth = 1;
  121. _rightButton.layer.borderColor = [UIColor whiteColor].CGColor;
  122. _rightButton.layer.borderWidth = 0;
  123. [_rightButton.layer setMasksToBounds:YES];
  124. [_rightButton.layer setCornerRadius:12.0];
  125. _rightButton.tag = 2; //为零,就不响应了
  126. [_rightButton addTarget:self action:@selector(click_Button:) forControlEvents:UIControlEventTouchUpInside];
  127. }
  128. return _rightButton;
  129. }
  130. - (void)click_Button:(UIButton *)btn
  131. {
  132. NSInteger tagg = (long)btn.tag;
  133. //NSLog(@"click_leftButton %ld", tagg);
  134. if(tagg>0)
  135. {
  136. [self.delegate AlertWith2ButtonViewDelegate:self.tag withButtonTag:tagg];
  137. }
  138. }
  139. @end