Files
peko-ios/YuMi/Modules/YMMine/View/SubViews/XPMineFriendNumberView.m

140 lines
4.0 KiB
Mathematica
Raw Normal View History

2023-07-06 16:54:13 +08:00
//
// YMMineFriendNumberView.m
// YUMI
//
// Created by YUMI on 2021/12/21.
//
2023-07-14 18:50:55 +08:00
#import "XPMineFriendNumberView.h"
///Third
2023-07-06 16:54:13 +08:00
#import <Masonry/Masonry.h>
2023-07-14 18:50:55 +08:00
///Tool
2023-07-06 16:54:13 +08:00
#import "DJDKMIMOMColor.h"
2023-10-28 04:46:10 +08:00
2023-07-06 16:54:13 +08:00
2023-07-14 18:50:55 +08:00
@interface XPMineFriendNumberView ()
///
2023-07-06 16:54:13 +08:00
@property (nonatomic,strong) UILabel *numberLabel;
2023-07-14 18:50:55 +08:00
///
2023-07-06 16:54:13 +08:00
@property (nonatomic,strong) UILabel *titleLabel;
2023-07-14 18:50:55 +08:00
//访
@property (nonatomic, strong) UILabel *unReadLabel;
2023-07-06 16:54:13 +08:00
@end
2023-07-14 18:50:55 +08:00
@implementation XPMineFriendNumberView
2023-07-06 16:54:13 +08:00
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
2023-07-14 18:50:55 +08:00
[self initSubViewConstraints];
2023-07-06 16:54:13 +08:00
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
[self addSubview:self.numberLabel];
[self addSubview:self.titleLabel];
}
2023-07-14 18:50:55 +08:00
- (void)initSubViewConstraints {
2023-07-06 16:54:13 +08:00
[self mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(self.titleLabel.mas_bottom);
}];
[self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self);
make.centerX.mas_equalTo(self);
// make.height.mas_equalTo(24);
2023-07-06 16:54:13 +08:00
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.numberLabel.mas_bottom).offset(4);
2024-04-11 17:05:27 +08:00
make.leading.trailing.mas_equalTo(self);
2023-07-06 16:54:13 +08:00
}];
}
2023-07-14 18:50:55 +08:00
- (NSAttributedString *)attributedStringWithLineSpace:(CGFloat)lineSpace str:(NSString *)str{
2023-07-06 16:54:13 +08:00
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] init];
NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:str attributes:@{NSForegroundColorAttributeName : UIColorFromRGB(0xffffff), NSFontAttributeName: kFontMedium(20)}];
2023-07-06 16:54:13 +08:00
[attributedString appendAttributedString:title];
attributedString.yy_alignment = NSTextAlignmentCenter;
return attributedString;
}
2023-07-14 18:50:55 +08:00
- (CGFloat)getWidthWithContent:(NSString *)content height:(CGFloat)height font:(CGFloat)font{
2023-07-06 16:54:13 +08:00
CGRect rect = [content boundingRectWithSize:CGSizeMake(999, height)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]}
context:nil];
return rect.size.width;
}
#pragma mark - Getters And Setters
- (void)setTitle:(NSString *)title {
self.titleLabel.text = title;
}
- (void)setNumber:(NSString *)number {
self.numberLabel.text = number;
}
2023-07-14 18:50:55 +08:00
- (void)setIsVisitor:(BOOL)isVisitor {
if (isVisitor) {
[self addSubview:self.unReadLabel];
[self.unReadLabel mas_makeConstraints:^(MASConstraintMaker *make) {
2025-03-21 16:19:07 +08:00
make.trailing.mas_equalTo(self).mas_offset(-12);
2023-07-06 16:54:13 +08:00
make.height.mas_equalTo(15);
2025-03-21 16:19:07 +08:00
make.top.mas_equalTo(self.numberLabel).offset(-10);
2023-07-06 16:54:13 +08:00
}];
}
}
2023-07-14 18:50:55 +08:00
- (void)setVisitorNum:(NSInteger)visitorNum {
if (visitorNum > 0) {
2025-03-21 16:19:07 +08:00
[self setIsVisitor:YES];
2023-07-14 18:50:55 +08:00
self.unReadLabel.hidden = NO;
2025-03-21 16:19:07 +08:00
self.unReadLabel.text = [NSString stringWithFormat:@"+%@", @(visitorNum)];
2023-07-06 16:54:13 +08:00
} else {
2023-07-14 18:50:55 +08:00
self.unReadLabel.hidden = YES;
2023-07-06 16:54:13 +08:00
}
}
- (UILabel *)numberLabel {
if (!_numberLabel) {
_numberLabel = [[UILabel alloc] init];
_numberLabel.font = kFontMedium(18);
2023-07-06 16:54:13 +08:00
_numberLabel.textAlignment = NSTextAlignmentCenter;
2023-07-14 18:50:55 +08:00
_numberLabel.textColor = [DJDKMIMOMColor mainTextColor];
2023-07-06 16:54:13 +08:00
}
return _numberLabel;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = kFontMedium(14);
_titleLabel.textColor = [DJDKMIMOMColor secondTextColor];
2023-07-06 16:54:13 +08:00
_titleLabel.textAlignment = NSTextAlignmentCenter;
}
return _titleLabel;
}
2023-07-14 18:50:55 +08:00
- (UILabel *)unReadLabel {
if (!_unReadLabel) {
_unReadLabel = [[UILabel alloc] init];
2025-03-21 16:19:07 +08:00
_unReadLabel.font = kFontSemibold(12);
_unReadLabel.textColor = UIColorFromRGB(0xff6868);
_unReadLabel.backgroundColor = [UIColor clearColor];
2023-07-14 18:50:55 +08:00
_unReadLabel.textAlignment = NSTextAlignmentCenter;
[_unReadLabel sizeToFit];
_unReadLabel.hidden = YES;
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
return _unReadLabel ;
2023-07-06 16:54:13 +08:00
}
@end