LivePayLeftPromptV.m 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. //
  2. // LivePayLeftPromptV.m
  3. // BuguLive
  4. //
  5. // Created by 丁凯 on 2017/8/16.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "LivePayLeftPromptV.h"
  9. @implementation LivePayLeftPromptV
  10. - (void)addFirstLabWithStr:(NSString *)labeStr
  11. {
  12. if (!self.firstLabel)
  13. {
  14. self.firstLabel = [[UILabel alloc]init];
  15. self.firstLabel.font = [UIFont systemFontOfSize:15];
  16. self.firstLabel.textColor = kWhiteColor;
  17. self.firstLabel.textAlignment = NSTextAlignmentCenter;
  18. self.firstLabel.backgroundColor = kGrayTransparentColor2;
  19. self.firstLabel.layer.cornerRadius = 11;
  20. self.firstLabel.layer.masksToBounds = YES;
  21. CGFloat labelW = [labeStr boundingRectWithSize:CGSizeMake(MAXFLOAT, kTicketContrainerViewHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size.width;
  22. self.firstLabel.frame = CGRectMake(0,kDefaultMargin, labelW+kTicketContrainerViewHeight, kTicketContrainerViewHeight);
  23. }
  24. else
  25. {
  26. CGFloat labelW = [labeStr boundingRectWithSize:CGSizeMake(MAXFLOAT, kTicketContrainerViewHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size.width;
  27. CGRect rect = self.firstLabel.frame;
  28. rect.size.width = labelW + kTicketContrainerViewHeight;
  29. self.firstLabel.frame = rect;
  30. }
  31. self.firstLabel.text = labeStr;
  32. [self addSubview:self.firstLabel];
  33. [self relayoutMyselfViewFrame];
  34. }
  35. - (void)addSecondLabWithStr:(NSString *)labeStr
  36. {
  37. if (!self.secondLabel)
  38. {
  39. self.secondLabel = [[UILabel alloc]init];
  40. self.secondLabel.font = [UIFont systemFontOfSize:15];
  41. self.secondLabel.textColor = kWhiteColor;
  42. self.secondLabel.textAlignment = NSTextAlignmentCenter;
  43. self.secondLabel.backgroundColor = kGrayTransparentColor2;
  44. self.secondLabel.layer.cornerRadius = 11;
  45. self.secondLabel.layer.masksToBounds = YES;
  46. CGFloat labelW = [labeStr boundingRectWithSize:CGSizeMake(MAXFLOAT, kTicketContrainerViewHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size.width;
  47. self.secondLabel.frame = CGRectMake(0, CGRectGetMaxY(self.firstLabel.frame)+8, labelW+kTicketContrainerViewHeight, kTicketContrainerViewHeight);
  48. }
  49. // else
  50. // {
  51. // CGFloat labelW = [labeStr boundingRectWithSize:CGSizeMake(MAXFLOAT, kTicketContrainerViewHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size.width;
  52. // CGRect rect = self.secondLabel.frame;
  53. // rect.size.height = labelW + kTicketContrainerViewHeight;
  54. // self.secondLabel.frame = rect;
  55. // }
  56. self.secondLabel.text = labeStr;
  57. [self addSubview:self.secondLabel];
  58. [self relayoutMyselfViewFrame];
  59. }
  60. - (void)addThreeLabWithStr:(NSString *)labeStr
  61. {
  62. if (!self.threeLabel)
  63. {
  64. self.threeLabel = [[UILabel alloc]init];
  65. self.threeLabel.font = [UIFont systemFontOfSize:15];
  66. self.threeLabel.textColor = kWhiteColor;
  67. self.threeLabel.textAlignment = NSTextAlignmentCenter;
  68. self.threeLabel.backgroundColor = kGrayTransparentColor2;
  69. self.threeLabel.layer.cornerRadius = 11;
  70. self.threeLabel.layer.masksToBounds = YES;
  71. CGFloat labelW = [labeStr boundingRectWithSize:CGSizeMake(MAXFLOAT, kTicketContrainerViewHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size.width;
  72. self.threeLabel.frame = CGRectMake(0,CGRectGetMaxY(self.secondLabel.frame)+8, labelW+kTicketContrainerViewHeight, kTicketContrainerViewHeight);
  73. }
  74. // else
  75. // {
  76. // CGFloat labelW = [labeStr boundingRectWithSize:CGSizeMake(MAXFLOAT, kTicketContrainerViewHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size.width;
  77. // CGRect rect = self.threeLabel.frame;
  78. // rect.size.height = labelW + kTicketContrainerViewHeight;
  79. // self.threeLabel.frame = rect;
  80. // }
  81. self.threeLabel.text = labeStr;
  82. [self addSubview:self.threeLabel];
  83. [self relayoutMyselfViewFrame];
  84. }
  85. - (void)removeFirstLabel
  86. {
  87. if (self.firstLabel)
  88. {
  89. [self.firstLabel removeFromSuperview];
  90. self.firstLabel = nil;
  91. }
  92. [self relayoutMyselfViewFrame];
  93. }
  94. - (void)removeSecondLabel
  95. {
  96. if (self.secondLabel)
  97. {
  98. [self.secondLabel removeFromSuperview];
  99. self.secondLabel = nil;
  100. }
  101. [self relayoutMyselfViewFrame];
  102. }
  103. - (void)removeThreeLabel
  104. {
  105. if (self.threeLabel)
  106. {
  107. [self.threeLabel removeFromSuperview];
  108. self.threeLabel = nil;
  109. }
  110. [self relayoutMyselfViewFrame];
  111. }
  112. - (void)relayoutMyselfViewFrame
  113. {
  114. self.myWidth = 0.0;
  115. CGFloat labelW1 = 0.0;
  116. CGFloat labelW2 = 0.0;
  117. CGFloat labelW3 = 0.0;
  118. if (self.firstLabel)
  119. {
  120. labelW1= [self.firstLabel.text boundingRectWithSize:CGSizeMake(MAXFLOAT, kTicketContrainerViewHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size.width + kTicketContrainerViewHeight;
  121. self.myHeight = 30;
  122. }
  123. if (self.secondLabel)
  124. {
  125. labelW2= [self.secondLabel.text boundingRectWithSize:CGSizeMake(MAXFLOAT, kTicketContrainerViewHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size.width + kTicketContrainerViewHeight;
  126. if (self.firstLabel)
  127. {
  128. CGRect rect = self.secondLabel.frame;
  129. rect.origin.x = 0;
  130. rect.origin.y = CGRectGetMaxY(self.firstLabel.frame)+8;
  131. rect.size.width = labelW2;
  132. rect.size.height = kTicketContrainerViewHeight;
  133. self.secondLabel.frame = rect;
  134. self.myHeight = 60;
  135. }else
  136. {
  137. CGRect rect = self.secondLabel.frame;
  138. rect.origin.x = 0;
  139. rect.origin.y = kDefaultMargin;
  140. rect.size.width = labelW2;
  141. rect.size.height = kTicketContrainerViewHeight;
  142. self.secondLabel.frame = rect;
  143. self.myHeight = 30;
  144. }
  145. }
  146. if (self.threeLabel)
  147. {
  148. labelW3= [self.threeLabel.text boundingRectWithSize:CGSizeMake(MAXFLOAT, kTicketContrainerViewHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size.width + kTicketContrainerViewHeight;
  149. if (self.firstLabel && self.secondLabel)
  150. {
  151. CGRect rect = self.threeLabel.frame;
  152. rect.origin.x = 0;
  153. rect.origin.y = CGRectGetMaxY(self.secondLabel.frame)+8;
  154. rect.size.width = labelW3;
  155. rect.size.height = kTicketContrainerViewHeight;
  156. self.threeLabel.frame = rect;
  157. self.myHeight = 90;
  158. }else if (self.firstLabel && !self.secondLabel)
  159. {
  160. CGRect rect = self.threeLabel.frame;
  161. rect.origin.x = 0;
  162. rect.origin.y = CGRectGetMaxY(self.firstLabel.frame)+8;
  163. rect.size.width = labelW3;
  164. rect.size.height = kTicketContrainerViewHeight;
  165. self.threeLabel.frame = rect;
  166. self.myHeight = 60;
  167. }else if (!self.firstLabel && self.secondLabel)
  168. {
  169. CGRect rect = self.threeLabel.frame;
  170. rect.origin.x = 0;
  171. rect.origin.y = CGRectGetMaxY(self.secondLabel.frame)+8;
  172. rect.size.width = labelW3;
  173. rect.size.height = kTicketContrainerViewHeight;
  174. self.threeLabel.frame = rect;
  175. self.myHeight = 60;
  176. }
  177. else
  178. {
  179. CGRect rect = self.threeLabel.frame;
  180. rect.origin.x = 0;
  181. rect.origin.y = kDefaultMargin;
  182. rect.size.width = labelW3;
  183. rect.size.height = kTicketContrainerViewHeight;
  184. self.threeLabel.frame = rect;
  185. self.myHeight = 30;
  186. }
  187. }
  188. if (self.myWidth < labelW1)
  189. {
  190. self.myWidth = labelW1;
  191. }
  192. if (self.myWidth < labelW2)
  193. {
  194. self.myWidth = labelW2;
  195. }
  196. if (self.myWidth < labelW3)
  197. {
  198. self.myWidth = labelW3;
  199. }
  200. CGRect rect = self.frame;
  201. rect.origin.x = kDefaultMargin;
  202. rect.origin.y = self.origin.y;
  203. rect.size.height = self.myHeight;
  204. rect.size.width = self.myWidth;
  205. self.frame = rect;
  206. self.backgroundColor = kClearColor;
  207. }
  208. - (void)updateMyFrameIsToUp:(BOOL)isUp andMyHeight:(CGFloat)myHeight
  209. {
  210. [UIView animateWithDuration:0.6 animations:^{
  211. if (isUp == YES)
  212. {
  213. CGRect rect = self.frame;
  214. rect.origin.y = rect.origin.y-myHeight;
  215. self.frame = rect;
  216. }else
  217. {
  218. CGRect rect = self.frame;
  219. rect.origin.y = rect.origin.y+myHeight;
  220. self.frame = rect;
  221. }
  222. }];
  223. }
  224. @end