Няма описание

PdDetailBottomView.m 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. //
  2. // PdDetailBottomView.m
  3. // FirstLink
  4. //
  5. // Created by jack on 15/7/17.
  6. // Copyright (c) 2015年 FirstLink. All rights reserved.
  7. //
  8. #import "PdDetailBottomView.h"
  9. #define kContentViewTagBase 120
  10. @implementation PdDetailBottomView
  11. - (instancetype)initWithFrame:(CGRect)frame
  12. {
  13. self = [super initWithFrame:frame];
  14. if (self) {
  15. [self initialize];
  16. }
  17. return self;
  18. }
  19. - (void)initialize
  20. {
  21. self.state = kPindanStateNormal;
  22. self.backgroundColor = [UIColor whiteColor];
  23. UIView *content0 = [[UIView alloc]init];
  24. UIView *content1 = [[UIView alloc]init];
  25. UIView *content2 = [[UIView alloc]init];
  26. UIView *topLine = [[UIView alloc]init];
  27. UIView *leftLine = [[UIView alloc]init];
  28. UIView *rightLine = [[UIView alloc]init];
  29. content0.backgroundColor = [UIColor clearColor];
  30. content1.backgroundColor = [UIColor clearColor];
  31. content2.backgroundColor = [UIColor clearColor];
  32. content0.tag = kContentViewTagBase + 0;
  33. content1.tag = kContentViewTagBase + 1;
  34. content2.tag = kContentViewTagBase + 2;
  35. topLine.backgroundColor = UIColorFromRGB(0xcccccc);
  36. leftLine.backgroundColor = UIColorFromRGB(0xe5e5e5);
  37. rightLine.backgroundColor = UIColorFromRGB(0xe5e5e5);
  38. [self addSubview:content0];
  39. [self addSubview:content1];
  40. [self addSubview:content2];
  41. [self addSubview:topLine];
  42. [self addSubview:leftLine];
  43. [self addSubview:rightLine];
  44. [self addSubview:self.commitBtn];
  45. [topLine mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.left.top.right.equalTo(self);
  47. make.height.equalTo(@0.5);
  48. }];
  49. [leftLine mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.top.equalTo(self).offset(10);
  51. make.bottom.equalTo(self).offset(- 10);
  52. make.left.equalTo(self).offset(55);
  53. make.width.equalTo(@0.5);
  54. }];
  55. [rightLine mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.top.bottom.width.equalTo(leftLine);
  57. make.left.equalTo(leftLine.mas_right).offset(55);
  58. }];
  59. [content0 mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.top.equalTo(topLine.mas_bottom);
  61. make.right.equalTo(leftLine.mas_left);
  62. make.left.bottom.equalTo(self);
  63. }];
  64. [content1 mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.left.equalTo(leftLine.mas_right);
  66. make.right.equalTo(rightLine.mas_left);
  67. make.bottom.equalTo(self);
  68. make.top.equalTo(topLine.mas_bottom);
  69. }];
  70. [content2 mas_makeConstraints:^(MASConstraintMaker *make) {
  71. make.left.equalTo(rightLine.mas_right);
  72. make.bottom.equalTo(self);
  73. make.top.equalTo(topLine.mas_bottom);
  74. make.width.equalTo(content1);
  75. }];
  76. [self.commitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  77. // make.right.equalTo(self).offset(- 15);
  78. // make.centerY.equalTo(self);
  79. // make.height.equalTo(@35);
  80. // make.width.equalTo(@125);
  81. make.top.right.bottom.equalTo(self);
  82. make.width.equalTo(@140);
  83. }];
  84. [self pvt_initialPartView:content0 withTitle:@"评论" normalImg:@"detail_comment_n" hlImg:@"detail_comment_h" btnTag:kBottomCommentBtnTag];
  85. [self pvt_initialPartView:content1 withTitle:@"分享" normalImg:@"detail_share_n" hlImg:@"detail_share_h" btnTag:kBottomShareBtnTag];
  86. [self pvt_initialPartView:content2 withTitle:@"客服" normalImg:@"detail_service_n" hlImg:@"detail_service_h" btnTag:kBottomServiceBtnTag];
  87. }
  88. - (void)pvt_initialPartView:(UIView *)content withTitle:(NSString *)title normalImg:(NSString *)imageName hlImg:(NSString *)highlightImg btnTag:(kBottomBtnTag)btnTag
  89. {
  90. UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:imageName]];
  91. UILabel *label = ({
  92. UILabel *label = [[UILabel alloc]init];
  93. label.backgroundColor = [UIColor clearColor];
  94. label.font = [UIFont systemFontOfSize:12];
  95. label.textColor = UIColorFromRGB(0x999999);
  96. label.textAlignment = NSTextAlignmentCenter;
  97. label.text = title;
  98. label;
  99. });
  100. UIButton *button = ({
  101. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  102. btn.tag = btnTag;
  103. [btn addTarget:self action:@selector(commitBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  104. btn;
  105. }); // 用于触发点击事件
  106. [content addSubview:imageView];
  107. [content addSubview:label];
  108. [content addSubview:button];
  109. [button mas_makeConstraints:^(MASConstraintMaker *make) {
  110. make.edges.insets(UIEdgeInsetsZero);
  111. }];
  112. [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.top.equalTo(content).offset(7);
  114. make.centerX.equalTo(content);
  115. }];
  116. [label mas_makeConstraints:^(MASConstraintMaker *make) {
  117. make.centerX.equalTo(imageView);
  118. // make.top.equalTo(imageView.mas_bottom).offset(3);
  119. make.bottom.equalTo(content).offset(- 4);
  120. }];
  121. }
  122. - (void)commitBtnClick:(UIButton *)sender
  123. {
  124. if ([self.delegate respondsToSelector:@selector(detailMenuBtnClickWithIndex:)]) {
  125. [self.delegate detailMenuBtnClickWithIndex:sender.tag];
  126. }
  127. }
  128. - (void)setState:(kPindanState)state
  129. {
  130. _state = state;
  131. NSString *title = nil;
  132. UIColor *titleColor = nil;
  133. switch (state) {
  134. case kPindanStateWaitBegin:{
  135. title = @"即将开启";
  136. titleColor = UIColorFromRGB(0x333333);
  137. }
  138. break;
  139. case kPindanStateNormal:{
  140. title = @"立即拼单";
  141. titleColor = UIColorFromRGB(0xff6362);
  142. }
  143. break;
  144. case kPindanStateRemind:{
  145. title = @"我想买";
  146. titleColor = UIColorFromRGB(0xfdc03c);
  147. }
  148. break;
  149. case kPindanStateCancelRemind:{
  150. title = @"已开启提醒";
  151. titleColor = UIColorFromRGB(0xcccccc);
  152. }
  153. break;
  154. case kPindanStateOnlyNew:{
  155. title = @"新用户专享";
  156. titleColor = UIColorFromRGB(0xcccccc);
  157. }
  158. break;
  159. case kPindanStateOnlyVIP:{
  160. title = @"会员专享";
  161. titleColor = UIColorFromRGB(0xcccccc);
  162. }
  163. break;
  164. case kPindanStateSaleDone:{
  165. title = @"我想买";
  166. titleColor = UIColorFromRGB(0xcccccc);
  167. }
  168. break;
  169. default:
  170. break;
  171. }
  172. [self.commitBtn setTitle:title forState:UIControlStateNormal];
  173. [self.commitBtn setBackgroundColor:titleColor];
  174. }
  175. - (UIButton *)commitBtn
  176. {
  177. if (_commitBtn == nil) {
  178. _commitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  179. [_commitBtn setTitle:@"立即拼单" forState:UIControlStateNormal];
  180. [_commitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  181. [_commitBtn setBackgroundColor:UIColorFromRGB(0xff6362)];
  182. [_commitBtn addTarget:self action:@selector(commitBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  183. _commitBtn.titleLabel.font = [UIFont systemFontOfSize:16];
  184. // _commitBtn.layer.cornerRadius = 5;
  185. _commitBtn.tag = kBottomConfirmBtnTag;
  186. }
  187. return _commitBtn;
  188. }
  189. @end