81 lines
3.0 KiB
Objective-C
81 lines
3.0 KiB
Objective-C
//
|
|
// SessionLimitChatView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by zu on 2021/12/8.
|
|
//
|
|
|
|
#import "SessionChatLimitView.h"
|
|
#import "ThemeColor.h"
|
|
#import "XPMacro.h"
|
|
#import "UIView+NIM.h"
|
|
#import "XPWebViewController.h"
|
|
#import <YYText/YYText.h>
|
|
#import <Masonry/Masonry.h>
|
|
#import <ReactiveObjC/ReactiveObjC.h>
|
|
|
|
@interface SessionChatLimitView()
|
|
|
|
@property (nonatomic, strong) UIView *bgView;
|
|
@property (nonatomic, strong) YYLabel *textLabel;
|
|
|
|
@end
|
|
|
|
@implementation SessionChatLimitView
|
|
|
|
- (instancetype)initWithChatLimit:(ChatLimitModel *)chatLimit {
|
|
if (self = [super initWithFrame:CGRectMake(0, 0, KScreenWidth, 50)]) {
|
|
[self addSubview:self.bgView];
|
|
[self.bgView addSubview:self.textLabel];
|
|
|
|
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.center.mas_equalTo(self);
|
|
}];
|
|
|
|
[self.textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.left.right.bottom.mas_equalTo(self.bgView).insets(UIEdgeInsetsMake(10, 10, 10, 10));
|
|
}];
|
|
|
|
[self initLabel:chatLimit.charmLevel.integerValue wealthLevel:chatLimit.wealthLevel.integerValue model:chatLimit.model];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)initLabel:(NSInteger)charmLevel wealthLevel:(NSInteger)wealthLevel model:(int)model{
|
|
if(model == 2){
|
|
NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:@"互相关注成为好友可发起聊天" attributes:@{NSFontAttributeName: [UIFont systemFontOfSize: 12],NSForegroundColorAttributeName: ThemeColor.mainTextColor}];
|
|
self.textLabel.attributedText = attStr;
|
|
return;
|
|
}
|
|
NSInteger charm = charmLevel > 0 ? charmLevel : 3;
|
|
NSInteger wealth = wealthLevel > 0 ? wealthLevel : 3;
|
|
UIColor *highlightColor = ThemeColor.appMainColor;
|
|
NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"仅财富等级≥%zd或魅力等级≥%zd的用户可发起聊天", wealth, charm] attributes:@{NSFontAttributeName: [UIFont systemFontOfSize: 12],NSForegroundColorAttributeName: ThemeColor.mainTextColor}];;
|
|
NSRange wealthLevelRange = [attStr.mutableString rangeOfString:[NSString stringWithFormat:@"财富等级≥%zd", wealth]];
|
|
NSRange charmLevelRange = [attStr.mutableString rangeOfString:[NSString stringWithFormat:@"魅力等级≥%zd", charm]];
|
|
[attStr yy_setColor:highlightColor range:wealthLevelRange];
|
|
[attStr yy_setColor:highlightColor range:charmLevelRange];
|
|
self.textLabel.attributedText = attStr;
|
|
}
|
|
|
|
- (UIView *)bgView {
|
|
if (!_bgView) {
|
|
_bgView = [UIView new];
|
|
_bgView.backgroundColor = ThemeColor.appCellBackgroundColor;
|
|
_bgView.layer.masksToBounds = YES;
|
|
_bgView.layer.cornerRadius = 8.0;
|
|
}
|
|
return _bgView;
|
|
}
|
|
|
|
- (YYLabel *)textLabel {
|
|
if (!_textLabel) {
|
|
_textLabel = [[YYLabel alloc] init];
|
|
_textLabel.textAlignment = NSTextAlignmentCenter;
|
|
_textLabel.numberOfLines = 0;
|
|
}
|
|
return _textLabel;
|
|
}
|
|
|
|
@end
|