XYMarkingFriendsMainSkillTopView.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // XYMarkingFriendsMainSkillTopView.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/12/7.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYMarkingFriendsMainSkillTopView.h"
  9. @interface XYMarkingFriendsMainSkillTopView ()
  10. @property (nonatomic, strong) UIView *matchUserView;
  11. @property (nonatomic, strong) UILabel *arrowTextLabel;
  12. @property (nonatomic, strong) UIImageView *arrowImageView;
  13. @property (nonatomic, strong) UIButton *quickMatchButton;
  14. @end
  15. @implementation XYMarkingFriendsMainSkillTopView
  16. - (void)setupMatchUserArray:(NSArray *)array {
  17. [_matchUserView removeFromSuperview];
  18. _matchUserView = nil;
  19. _matchUserView = [[UIView alloc] init];
  20. _matchUserView.backgroundColor = [UIColor clearColor];
  21. [self addSubview:_matchUserView];
  22. [_matchUserView mas_makeConstraints:^(MASConstraintMaker *make) {
  23. make.left.equalTo(self).offset(16.0f);
  24. make.centerY.equalTo(self);
  25. make.width.equalTo(@84.0f);
  26. make.height.equalTo(@24.0f);
  27. }];
  28. [_matchUserView layoutIfNeeded];
  29. UIImageView *tempView;
  30. for (int i = 0; i < array.count; i++) {
  31. XYUserModel *model = array[i];
  32. if (i < 4) {
  33. UIImageView *avatarImgView = [[UIImageView alloc] init];
  34. [avatarImgView sd_setImageWithURL:[NSURL URLWithString:model.userAvatar] placeholderImage:placeholderUserMainBgImage(model.userSex)];
  35. avatarImgView.contentMode = UIViewContentModeScaleAspectFill;
  36. [_matchUserView addSubview:avatarImgView];
  37. [avatarImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  38. if (tempView) { make.left.equalTo(tempView).offset(20.0f); }
  39. else{ make.left.equalTo(self).offset(20.0f); }
  40. make.centerY.equalTo(self);
  41. make.width.equalTo(@24.0f);
  42. make.height.equalTo(@24.0f);
  43. }];
  44. [avatarImgView layoutIfNeeded];
  45. kViewRadius(avatarImgView, 12);
  46. tempView = avatarImgView;
  47. }
  48. }
  49. }
  50. #pragma mark — Action
  51. - (void)quickMatchButtonAction:(id)sender {
  52. if (self.quickMatchBlock) {
  53. self.quickMatchBlock();
  54. }
  55. }
  56. - (instancetype)init
  57. {
  58. self = [super init];
  59. if (self) {
  60. [self setupUI];
  61. }
  62. return self;
  63. }
  64. - (instancetype)initWithFrame:(CGRect)frame
  65. {
  66. self = [super initWithFrame:frame];
  67. if (self) {
  68. [self setupUI];
  69. }
  70. return self;
  71. }
  72. - (void)setupUI {
  73. [self addSubview:self.arrowTextLabel];
  74. [self addSubview:self.arrowImageView];
  75. [self addSubview:self.quickMatchButton];
  76. [self.arrowTextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.center.equalTo(self);
  78. }];
  79. [self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.right.equalTo(self.arrowTextLabel.mas_left).offset(-4.0f);
  81. make.centerY.equalTo(self.arrowTextLabel);
  82. make.width.height.equalTo(@6.0f);
  83. }];
  84. [self.quickMatchButton mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.right.equalTo(self).offset(-16.0f);
  86. make.centerY.equalTo(self);
  87. make.width.equalTo(@64.0f);
  88. make.height.equalTo(@22.0f);
  89. }];
  90. [self.quickMatchButton addViewBorder:Color_Clear redian:11];
  91. }
  92. #pragma mark — Getter
  93. - (UILabel *)arrowTextLabel {
  94. if (!_arrowTextLabel) {
  95. _arrowTextLabel = [UILabel createLabelTextColor:ColorFromHexStringWithAlpha(@"#D4C1FF", 0.5f) fount:Font(10)];
  96. _arrowTextLabel.textAlignment = NSTextAlignmentCenter;
  97. _arrowTextLabel.text = kLocalizedString(@"下拉快速匹配");
  98. }
  99. return _arrowTextLabel;
  100. }
  101. - (UIImageView *)arrowImageView {
  102. if (!_arrowImageView) {
  103. _arrowImageView = [UIImageView new];
  104. _arrowImageView.image = ImageNamed(@"xy_friend_skill_arrow");
  105. }
  106. return _arrowImageView;
  107. }
  108. - (UIButton *)quickMatchButton {
  109. if (!_quickMatchButton) {
  110. _quickMatchButton = [UIButton createButtonTextColor:Color_White textFont:Font(10)];
  111. [_quickMatchButton setTitle:kLocalizedString(@"快速匹配") forState:UIControlStateNormal];
  112. [_quickMatchButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[ColorFromHexString(@"#5F0AFF"), ColorFromHexString(@"#9858FF")] gradientType:GradientTypeUpleftToLowright imgSize:CGSizeMake(64.0f, 22.0f)] forState:UIControlStateNormal];
  113. [_quickMatchButton addTarget:self action:@selector(quickMatchButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  114. }
  115. return _quickMatchButton;
  116. }
  117. @end