95 lines
2.9 KiB
Objective-C
95 lines
2.9 KiB
Objective-C
//
|
|
// XPRoomMessageHeaderView.m
|
|
// yinmeng-ios
|
|
//
|
|
// Created by 触海 on 2023/11/21.
|
|
//
|
|
|
|
#import "CHRoomMessageHeaderView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "ThemeColor+Room.h"
|
|
#import "YMRoomMessageConstant.h"
|
|
#import "YMMacro.h"
|
|
|
|
@interface CHRoomMessageHeaderView ()
|
|
///背景
|
|
@property (nonatomic,strong) UIView *bubbleBgView;
|
|
///显示
|
|
@property (nonatomic,strong) UILabel *titleTextLabel;
|
|
@end
|
|
|
|
@implementation CHRoomMessageHeaderView
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
{
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
return self;
|
|
}
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[self addSubview:self.bubbleBgView];
|
|
[self addSubview:self.titleTextLabel];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
/// 设置绿色消息
|
|
NSString *title = @"平台严禁未成年人直播或打赏,倡导绿色互动,禁止宣传及发布政治、低俗、暴力、色情等违规违法内容,严禁违规交易和诱导欺诈用户,如有发现请及时举报。";
|
|
self.titleTextLabel.text = title;
|
|
CGFloat height = [self getHeaderViewHeight:title] + kRoomMessageTextSpace *2;
|
|
[self mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.mas_equalTo(kRoomMessageMaxWidth);
|
|
make.height.mas_equalTo(height);
|
|
}];
|
|
|
|
[self.bubbleBgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.top.right.mas_equalTo(self);
|
|
make.bottom.mas_equalTo(self).offset(-10);
|
|
}];
|
|
|
|
[self.titleTextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.mas_equalTo(self).inset(10);
|
|
make.centerY.mas_equalTo(self.bubbleBgView);
|
|
}];
|
|
}
|
|
|
|
///获取头部的高度
|
|
- (CGFloat)getHeaderViewHeight:(NSString *)title {
|
|
return [title boundingRectWithSize:CGSizeMake(kRoomMessageMaxWidth - 20, CGFLOAT_MAX) options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:kRoomMessageTextFont]} context:nil].size.height;
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setBubbleColor:(UIColor *)bubbleColor {
|
|
_bubbleColor = bubbleColor;
|
|
if (_bubbleColor) {
|
|
_bubbleBgView.backgroundColor = _bubbleColor;
|
|
}
|
|
}
|
|
|
|
- (UIView *)bubbleBgView {
|
|
if (!_bubbleBgView) {
|
|
_bubbleBgView = [[UIView alloc] init];
|
|
_bubbleBgView.backgroundColor = [ThemeColor messageBubbleColor];
|
|
_bubbleBgView.layer.masksToBounds = YES;
|
|
_bubbleBgView.layer.cornerRadius = kRoomMessageBubbleCornerRadius;
|
|
}
|
|
return _bubbleBgView;
|
|
}
|
|
|
|
- (UILabel *)titleTextLabel {
|
|
if (!_titleTextLabel) {
|
|
_titleTextLabel = [[UILabel alloc] init];
|
|
_titleTextLabel.font = [UIFont systemFontOfSize:kRoomMessageTextFont];
|
|
_titleTextLabel.textColor = UIColor.whiteColor;
|
|
_titleTextLabel.numberOfLines = 0;
|
|
}
|
|
return _titleTextLabel;
|
|
}
|
|
|
|
@end
|