YBPkProgressView.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // YBPkProgressView.m
  3. // yunbaolive
  4. //
  5. // Created by Boom on 2018/11/14.
  6. // Copyright © 2018年 cat. All rights reserved.
  7. //
  8. #import "YBPkProgressView.h"
  9. @implementation YBPkProgressView{
  10. UIView *redView;
  11. UIView *blueView;
  12. UILabel *redLabel;
  13. UILabel *blueLabel;
  14. }
  15. - (instancetype)initWithFrame:(CGRect)frame{
  16. self = [super initWithFrame:frame];
  17. if (self) {
  18. [self creatUI];
  19. }
  20. return self;
  21. }
  22. - (void)creatUI{
  23. blueView = [[UIView alloc]init];
  24. blueView.backgroundColor = RGB_COLOR(@"#167EFF", 0.5);
  25. blueView.layer.borderColor = RGB_COLOR(@"#3393FF", 1).CGColor;
  26. blueView.layer.borderWidth = 1;
  27. [self addSubview:blueView];
  28. [blueView mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.left.equalTo(self).offset(-_window_width/2);
  30. make.top.height.equalTo(self);
  31. make.width.equalTo(self).multipliedBy(0.5);
  32. }];
  33. UILabel *woLabel = [[UILabel alloc]init];
  34. woLabel.font = [UIFont systemFontOfSize:11];
  35. woLabel.textColor = [UIColor whiteColor];
  36. woLabel.text = YZMsg(@"我方");
  37. [blueView addSubview:woLabel];
  38. [woLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.top.height.equalTo(blueView);
  40. make.left.equalTo(blueView).offset(5);
  41. }];
  42. blueLabel = [[UILabel alloc]init];
  43. blueLabel.font = [UIFont systemFontOfSize:11];
  44. blueLabel.textColor = [UIColor whiteColor];
  45. blueLabel.text = @"0";
  46. [blueView addSubview:blueLabel];
  47. [blueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.top.equalTo(blueView.mas_top);
  49. // make.right.equalTo(blueView.mas_right).offset(-3);
  50. make.left.equalTo(woLabel.mas_right).offset(3);
  51. make.bottom.equalTo(blueView.mas_bottom);
  52. }];
  53. redView = [[UIView alloc]initWithFrame:CGRectMake(_window_width, 0, _window_width/2, 20)];
  54. redView.backgroundColor = RGB_COLOR(@"#FF3D3D", 0.5);
  55. redView.layer.borderColor = RGB_COLOR(@"#F93232", 1).CGColor;
  56. redView.layer.borderWidth = 1;
  57. [self addSubview:redView];
  58. [redView mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.right.equalTo(self).offset(_window_width/2);
  60. make.top.height.equalTo(self);
  61. make.width.equalTo(self).multipliedBy(0.5);
  62. }];
  63. UILabel *duiLabel = [[UILabel alloc]init];
  64. duiLabel.font = [UIFont systemFontOfSize:11];
  65. duiLabel.textColor = [UIColor whiteColor];
  66. duiLabel.text = YZMsg(@"对方");
  67. [redView addSubview:duiLabel];
  68. [duiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.top.height.equalTo(redView);
  70. make.right.equalTo(redView).offset(-5);
  71. }];
  72. redLabel = [[UILabel alloc]init];
  73. redLabel.font = [UIFont systemFontOfSize:11];
  74. redLabel.textColor = [UIColor whiteColor];
  75. redLabel.text = @"0";
  76. redLabel.textAlignment = NSTextAlignmentRight;
  77. [redView addSubview:redLabel];
  78. [redLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.top.equalTo(redView.mas_top);
  80. // make.left.equalTo(redView.mas_left).offset(3);
  81. make.right.equalTo(duiLabel.mas_left).offset(-3);
  82. make.bottom.equalTo(redView.mas_bottom);
  83. }];
  84. [self layoutIfNeeded];
  85. [UIView animateWithDuration:0.8 animations:^{
  86. [blueView mas_updateConstraints:^(MASConstraintMaker *make) {
  87. make.left.equalTo(self);
  88. }];
  89. [redView mas_updateConstraints:^(MASConstraintMaker *make) {
  90. make.right.equalTo(self);
  91. }];
  92. }];
  93. }
  94. - (void)updateProgress:(CGFloat)progress withBlueNum:(NSString *)blueNum withRedNum:(NSString *)redNum{
  95. blueLabel.text = blueNum;
  96. redLabel.text = redNum;
  97. [blueView mas_remakeConstraints:^(MASConstraintMaker *make) {
  98. make.width.mas_equalTo(_window_width*progress);
  99. make.left.equalTo(self);
  100. make.top.height.equalTo(self);
  101. }];
  102. [redView mas_remakeConstraints:^(MASConstraintMaker *make) {
  103. make.width.mas_equalTo(_window_width*(1-progress));
  104. make.top.height.equalTo(self);
  105. make.right.equalTo(self);
  106. }];
  107. }
  108. @end