ASUserAvaterView.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // ASUserAvaterView.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/5/15.
  6. //
  7. #import "ASUserAvaterView.h"
  8. @interface ASUserAvaterView ()
  9. @property (nonatomic, strong) UIView *bgColorV;
  10. @property (nonatomic, strong) UIImageView *imgV;
  11. @property (nonatomic, strong) UILabel *nameLb;
  12. @end
  13. @implementation ASUserAvaterView
  14. - (void)setUserHeadV:(NSString *)avater uName:(NSString *)uName {
  15. if (avater && ![avater isEqualToString:@""]) {
  16. [self.imgV sd_setImageWithURL:[NSURL URLWithString:avater]];
  17. [self setBorderColor:_113632 width:0];
  18. } else {
  19. self.nameLb.text = [[uName substringToIndex:1] uppercaseString];
  20. [self setBorderColor:_113632 width:2];
  21. }
  22. }
  23. - (void)setBorderColor:(UIColor *)color width:(CGFloat)w {
  24. self.layer.borderColor = color.CGColor;
  25. self.layer.borderWidth = w;
  26. }
  27. - (void)setCorner:(CGFloat)cor {
  28. self.layer.cornerRadius = cor;
  29. self.layer.masksToBounds = true;
  30. }
  31. - (instancetype)initWithFrame:(CGRect)frame {
  32. self = [super initWithFrame:frame];
  33. if (self) {
  34. CGFloat min = MIN(frame.size.width, frame.size.height);
  35. self.nameLb.font = [UIFont fontWithName:Rob_Bold size:min/100*52];
  36. [self loadSubV];
  37. }
  38. return self;
  39. }
  40. - (void)loadSubV {
  41. [self addSubview:self.bgColorV];
  42. [self addSubview:self.nameLb];
  43. [self addSubview:self.imgV];
  44. [self.bgColorV mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.edges.equalTo(self);
  46. }];
  47. [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.top.leading.equalTo(self).offset(6);
  49. make.bottom.trailing.equalTo(self).offset(-6);
  50. }];
  51. [self.imgV mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.edges.equalTo(self);
  53. }];
  54. dispatch_async(dispatch_get_main_queue(), ^{
  55. [UIView viewAddHorColorBg:self.bgColorV colorArr:@[
  56. (id)_C8FFED.CGColor,
  57. (id)Col_FFF.CGColor
  58. ]];
  59. });
  60. }
  61. - (UIView *)bgColorV {
  62. if (!_bgColorV) {
  63. UIView *v = [UIView baseV];
  64. v.backgroundColor = UIColor.whiteColor;
  65. _bgColorV = v;
  66. }
  67. return _bgColorV;
  68. }
  69. - (UIImageView *)imgV {
  70. if (!_imgV) {
  71. UIImageView *v = [UIImageView baseImgV];
  72. v.contentMode = UIViewContentModeScaleAspectFill;
  73. _imgV = v;
  74. }
  75. return _imgV;
  76. }
  77. - (UILabel *)nameLb {
  78. if (!_nameLb) {
  79. UILabel *lb = [UILabel baseLb];
  80. lb.font = [UIFont fontWithName:Rob_Bold size:48];
  81. lb.textColor = _113632;
  82. lb.textAlignment = NSTextAlignmentCenter;
  83. _nameLb = lb;
  84. }
  85. return _nameLb;
  86. }
  87. @end