101 lines
3.5 KiB
Objective-C
101 lines
3.5 KiB
Objective-C
//
|
|
// MessageContentRiskAlertView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/8/11.
|
|
//
|
|
|
|
#import "MessageContentRiskAlertView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <YYText/YYText.h>
|
|
#import "ContentRistAlertModel.h"
|
|
#import "NSObject+MJExtension.h"
|
|
#import "ThemeColor.h"
|
|
#import "XCCurrentVCStackManager.h"
|
|
#import "XPHtmlUrl.h"
|
|
#import "XPWebViewController.h"
|
|
|
|
@interface MessageContentRiskAlertView ()
|
|
///显示内容
|
|
@property (nonatomic,strong) YYLabel *contentLabel;
|
|
@end
|
|
|
|
@implementation MessageContentRiskAlertView
|
|
|
|
+ (CGFloat)measureHeight:(NIMMessage *)message {
|
|
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
|
|
AttachmentModel * attach = obj.attachment;
|
|
ContentRistAlertModel * model = [ContentRistAlertModel modelWithDictionary:attach.data];
|
|
NSString * text = model.content;
|
|
if (text.length <= 0) {
|
|
text = @"";
|
|
}
|
|
CGSize dstRect = CGSizeMake(CONTENT_WIDTH_MAX - MESSAGE_PADDING * 2, MAXFLOAT);
|
|
CGFloat msgHeight = [text boundingRectWithSize:dstRect options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine attributes:[self messageTextAttibutes] context:nil].size.height;
|
|
return msgHeight + MESSAGE_PADDING * 2 + CONTENT_PADDING_V_TOTAL;
|
|
}
|
|
|
|
+ (NSDictionary<NSAttributedStringKey, id> *)messageTextAttibutes {
|
|
UIFont *font = [UIFont systemFontOfSize:13.f];
|
|
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
|
|
[paragraphStyle setLineSpacing:2.5];
|
|
return @{
|
|
NSFontAttributeName:font,
|
|
NSParagraphStyleAttributeName: paragraphStyle
|
|
};
|
|
}
|
|
|
|
- (void)initSubViews {
|
|
[super initSubViews];
|
|
// self.backView.backgroundColor = [ThemeColor colorWithHexString:@"#e8e8e8"];
|
|
// self.backView.layer.masksToBounds = YES;
|
|
// self.backView.layer.cornerRadius = 10;
|
|
[self.backView addSubview:self.contentLabel];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[super initSubViewConstraints];
|
|
[self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self.backView);
|
|
}];
|
|
}
|
|
|
|
|
|
- (void)render:(nonnull NIMMessage *)message {
|
|
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
|
|
AttachmentModel * attach = obj.attachment;
|
|
ContentRistAlertModel * model = [ContentRistAlertModel modelWithDictionary:attach.data];
|
|
NSString * text = model.content;
|
|
if (text.length <= 0) {
|
|
text = @"";
|
|
}
|
|
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] initWithString:text attributes:[MessageContentRiskAlertView messageTextAttibutes]];
|
|
NSRange range = [text rangeOfString:@"《整治网络直播乱象》"];
|
|
if ((range.location + range.length) <= text.length) {
|
|
[attribute addAttribute:NSForegroundColorAttributeName value:[ThemeColor appEmphasizeColor] range:range];
|
|
|
|
}
|
|
|
|
[attribute yy_setTextHighlightRange:NSMakeRange(0, attribute.length) color:nil backgroundColor:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
|
|
XPWebViewController * webVC = [[XPWebViewController alloc] init];
|
|
webVC.url = URLWithType(kNetworkRenovateURL);
|
|
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:webVC animated:YES];
|
|
}];
|
|
self.contentLabel.attributedText = attribute;
|
|
|
|
}
|
|
|
|
- (YYLabel *)contentLabel {
|
|
if (!_contentLabel) {
|
|
_contentLabel = [[YYLabel alloc]initWithFrame:CGRectZero];
|
|
_contentLabel.preferredMaxLayoutWidth = CONTENT_WIDTH_MAX - MESSAGE_PADDING * 2;
|
|
_contentLabel.textColor = ThemeColor.mainTextColor;
|
|
_contentLabel.numberOfLines = 0;
|
|
}
|
|
return _contentLabel;
|
|
}
|
|
|
|
|
|
@end
|