123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- //
- // ASUserAvaterView.m
- // Asteria
- //
- // Created by iOS on 2023/5/15.
- //
- #import "ASUserAvaterView.h"
- @interface ASUserAvaterView ()
- @property (nonatomic, strong) UIView *bgColorV;
- @property (nonatomic, strong) UIImageView *imgV;
- @property (nonatomic, strong) UILabel *nameLb;
- @end
- @implementation ASUserAvaterView
- - (void)setUserHeadV:(NSString *)avater uName:(NSString *)uName {
- if (avater && ![avater isEqualToString:@""]) {
- [self.imgV sd_setImageWithURL:[NSURL URLWithString:avater]];
- [self setBorderColor:_113632 width:0];
- } else {
- self.nameLb.text = [[uName substringToIndex:1] uppercaseString];
- [self setBorderColor:_113632 width:2];
-
- }
- }
- - (void)setBorderColor:(UIColor *)color width:(CGFloat)w {
- self.layer.borderColor = color.CGColor;
- self.layer.borderWidth = w;
- }
- - (void)setCorner:(CGFloat)cor {
- self.layer.cornerRadius = cor;
- self.layer.masksToBounds = true;
- }
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- CGFloat min = MIN(frame.size.width, frame.size.height);
- self.nameLb.font = [UIFont fontWithName:Rob_Bold size:min/100*52];
- [self loadSubV];
- }
- return self;
- }
- - (void)loadSubV {
- [self addSubview:self.bgColorV];
- [self addSubview:self.nameLb];
- [self addSubview:self.imgV];
-
- [self.bgColorV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self);
- }];
- [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.leading.equalTo(self).offset(6);
- make.bottom.trailing.equalTo(self).offset(-6);
- }];
- [self.imgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self);
- }];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [UIView viewAddHorColorBg:self.bgColorV colorArr:@[
- (id)_C8FFED.CGColor,
- (id)Col_FFF.CGColor
- ]];
- });
-
-
-
- }
- - (UIView *)bgColorV {
- if (!_bgColorV) {
- UIView *v = [UIView baseV];
- v.backgroundColor = UIColor.whiteColor;
- _bgColorV = v;
- }
- return _bgColorV;
- }
- - (UIImageView *)imgV {
- if (!_imgV) {
- UIImageView *v = [UIImageView baseImgV];
- v.contentMode = UIViewContentModeScaleAspectFill;
- _imgV = v;
- }
- return _imgV;
- }
- - (UILabel *)nameLb {
- if (!_nameLb) {
- UILabel *lb = [UILabel baseLb];
- lb.font = [UIFont fontWithName:Rob_Bold size:48];
- lb.textColor = _113632;
- lb.textAlignment = NSTextAlignmentCenter;
- _nameLb = lb;
- }
- return _nameLb;
- }
- @end
|