《省钱达人》与《猎豆优选》UI相同版。域名tbk

DRSearchCoupleBottomView.m 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // DRSearchCoupleBottomView.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/11/27.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRSearchCoupleBottomView.h"
  9. #import "DRGoodDetailModel.h"
  10. #define buttonWidth (SCREEN_WIDTH-20)
  11. @interface DRSearchCoupleBottomView ()
  12. @property (nonatomic, strong) UIButton *searchBtn;
  13. @property (nonatomic, strong) UIButton *payBtn;
  14. @property (nonatomic, strong) UIButton *discountBtn;
  15. @end
  16. @implementation DRSearchCoupleBottomView
  17. - (instancetype)initWithFrame:(CGRect)frame
  18. {
  19. self = [super initWithFrame:frame];
  20. if (self) {
  21. self.backgroundColor = [UIColor homeRedColor];
  22. [self initUI];
  23. }
  24. return self;
  25. }
  26. - (void)initUI {
  27. [self addSubview:self.searchBtn];
  28. [self addSubview:self.payBtn];
  29. [self addSubview:self.discountBtn];
  30. }
  31. - (void)showSearch {
  32. self.searchBtn.hidden = NO;
  33. self.payBtn.hidden = YES;
  34. self.discountBtn.hidden = YES;
  35. }
  36. - (void)showPay {
  37. self.searchBtn.hidden = YES;
  38. self.payBtn.hidden = NO;
  39. }
  40. - (void)searchCouple {
  41. if (self.delegate && [self.delegate respondsToSelector:@selector(bottomViewSearchClick)]) {
  42. [self.delegate bottomViewSearchClick];
  43. }
  44. }
  45. - (void)payAction {
  46. if ([self.delegate respondsToSelector:@selector(bottomViewPayClick)]) {
  47. [self.delegate bottomViewPayClick];
  48. }
  49. }
  50. - (UIButton *)searchBtn {
  51. if (!_searchBtn) {
  52. _searchBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 5, buttonWidth, 40)];
  53. [_searchBtn setTitle:@"搜索优惠券" forState:UIControlStateNormal];
  54. [_searchBtn setImage:[UIImage imageNamed:@"sousuo"] forState:UIControlStateNormal];
  55. [_searchBtn setButtonImageTitleStyle:ButtonImageTitleStyleLeft padding:7];
  56. _searchBtn.backgroundColor=[UIColor YHColorWithHex:0xFA2C36];
  57. _searchBtn.layer.cornerRadius=20;
  58. _searchBtn.layer.masksToBounds=YES;
  59. _searchBtn.titleLabel.font = [UIFont systemFontOfSize:15];
  60. [_searchBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  61. [_searchBtn addTarget:self action:@selector(searchCouple) forControlEvents:UIControlEventTouchUpInside];
  62. }
  63. return _searchBtn;
  64. }
  65. -(UIButton *)discountBtn
  66. {
  67. if (!_discountBtn) {
  68. _discountBtn = [[UIButton alloc] initWithFrame:CGRectMake(10+buttonWidth/3, 5, buttonWidth/3, self.height-10)];
  69. _discountBtn.hidden=YES;
  70. [_discountBtn setTitle:@"券" forState:UIControlStateNormal];
  71. [_discountBtn setImage:[UIImage imageNamed:@"quan-2"] forState:UIControlStateNormal];
  72. _discountBtn.titleLabel.font = [UIFont systemFontOfSize:15];
  73. _discountBtn.backgroundColor = [UIColor YHColorWithHex:0xFA2C36];
  74. [_discountBtn setButtonImageTitleStyle:ButtonImageTitleStyleLeft padding:7];
  75. [_discountBtn addTarget:self action:@selector(payAction) forControlEvents:UIControlEventTouchUpInside];
  76. }
  77. return _discountBtn;
  78. }
  79. - (UIButton *)payBtn {
  80. if (!_payBtn) {
  81. _payBtn = [[UIButton alloc] initWithFrame:CGRectMake(buttonWidth/3+10.5, 5, buttonWidth/3, self.height-10)];
  82. [_payBtn setTitle:@"立即购买" forState:UIControlStateNormal];
  83. _payBtn.backgroundColor = [UIColor YHColorWithHex:0xFA2C36];
  84. _payBtn.titleLabel.font = [UIFont systemFontOfSize:15];
  85. [_payBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  86. [_payBtn addTarget:self action:@selector(payAction) forControlEvents:UIControlEventTouchUpInside];
  87. // 设置圆角
  88. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_payBtn.bounds byRoundingCorners:UIRectCornerBottomRight | UIRectCornerTopRight cornerRadii:CGSizeMake(self.height/2, self.height/2)];
  89. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  90. maskLayer.frame = _payBtn.bounds;
  91. maskLayer.path = maskPath.CGPath;
  92. _payBtn.layer.mask = maskLayer;
  93. }
  94. return _payBtn;
  95. }
  96. -(void)setModel:(DRGoodDetailModel *)model
  97. {
  98. _model=model;
  99. if (model.is_coupon.integerValue != 1) {//无券的时候
  100. self.discountBtn.hidden=YES;
  101. self.payBtn.frame=CGRectMake(10, 5, SCREEN_WIDTH-20, self.height-10);
  102. [self paycorner:UIRectCornerBottomRight | UIRectCornerTopRight|UIRectCornerBottomLeft|UIRectCornerTopLeft];
  103. [self.payBtn setImage:[UIImage imageNamed:@"quan-2"] forState:UIControlStateNormal];
  104. [self.payBtn setButtonImageTitleStyle:ButtonImageTitleStyleLeft padding:7];
  105. }else{
  106. [self.payBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
  107. self.discountBtn.hidden=NO;
  108. [self.discountBtn setTitle:[NSString stringWithFormat:@"%@元",model.coupon_price] forState:UIControlStateNormal];
  109. self.discountBtn.frame=CGRectMake(10, 5, buttonWidth/3, self.height-10);
  110. self.payBtn.frame=CGRectMake(10.5+buttonWidth/3, 5, buttonWidth/3*2, self.height-10);
  111. [self paycorner:UIRectCornerBottomRight | UIRectCornerTopRight];
  112. [self discountcorner];
  113. }
  114. }
  115. -(void)paycorner:(UIRectCorner)reconer
  116. {
  117. // 设置圆角
  118. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_payBtn.bounds byRoundingCorners:reconer cornerRadii:CGSizeMake(self.height/2, self.height/2)];
  119. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  120. maskLayer.frame = _payBtn.bounds;
  121. maskLayer.path = maskPath.CGPath;
  122. _payBtn.layer.mask = maskLayer;
  123. }
  124. -(void)discountcorner
  125. {
  126. UIBezierPath *maskPath1 = [UIBezierPath bezierPathWithRoundedRect:_discountBtn.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(self.height/2, self.height/2)];
  127. CAShapeLayer *maskLayer1 = [[CAShapeLayer alloc] init];
  128. maskLayer1.frame = _discountBtn.bounds;
  129. maskLayer1.path = maskPath1.CGPath;
  130. _discountBtn.layer.mask = maskLayer1;
  131. }
  132. @end