123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- //
- // YOUPAILZLiveBarrageTool.m
- // VQU
- //
- // Created by CY on 2021/8/30.
- // Copyright © 2021 MS. All rights reserved.
- //
- #import "YOUPAILZLiveBarrageTool.h"
- #import "YOUPAILZAvatarView.h"
- #import "YOUPAILZLevelView.h"
- @implementation YOUPAILZLiveBarrageTool
- /// 处理VIP进场弹幕消息
- + (UIView *)youpaifhandleVipBarrageAttachment:(YOUPAILZLiveVipBarrageAttachment *)barrageAttachment{
- UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 220.0f, 43.0f)];
-
- UIImageView *boxImgV = [[UIImageView alloc] initWithFrame:CGRectMake(17.5f, 7.0f, bgV.mj_w - 17.5f, bgV.mj_h - 7.0f)];
- [boxImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:barrageAttachment.b_box]];
- [bgV addSubview:boxImgV];
-
- YOUPAILZAvatarView *youpaipavatarView = [YOUPAILZAvatarView youpaifavatarViewWithFrame:CGRectMake(0, 0, 34.0f, 34.0f) avatarURL:[LCTools getImageUrlWithAddress:barrageAttachment.avatar] personalityBoxURL:[LCTools getImageUrlWithAddress:barrageAttachment.avatar_frame]];
- [bgV addSubview:youpaipavatarView];
- [youpaipavatarView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(0.0f);
- make.centerY.equalTo(bgV);
- make.size.mas_offset(CGSizeMake(34.0f, 34.0f));
- }];
-
- UILabel *descL = [[UILabel alloc] initWithFrame:CGRectMake(30.0f, 4.0f, boxImgV.mj_w - (30.0f + 20.0f), 25.0f)];
- descL.textColor = [UIColor whiteColor];
- descL.font = LCFont13;
- // descL.text = barrageAttachment.des;
- [boxImgV addSubview:descL];
-
- if (barrageAttachment.name.length > 3) {
- barrageAttachment.name = [NSString stringWithFormat:@"%@…",[barrageAttachment.name substringToIndex:3]];
- }
-
- NSString *moneyText = barrageAttachment.noble_name;
- NSRange priceRange = NSMakeRange(moneyText.length + 1, barrageAttachment.name.length);
- moneyText = [NSString stringWithFormat:@"%@ %@ 驾临!",moneyText,barrageAttachment.name];
-
- NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:moneyText];
- [attrStr addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0xFFDD8D) range:priceRange];
- descL.attributedText = attrStr;
-
- return bgV;
- }
- /// 处理榜单进场弹幕消息
- + (UIView *)youpaifhandleBarrageAttachment:(YOUPAILZLiveBarrageAttachment *)barrageAttachment{
- UIView *bgV = [[UIView alloc] init];
-
- UIView *barrageView = [[UIView alloc] init];
- barrageView.backgroundColor = [UIColor clearColor];
- [bgV addSubview:barrageView];
- [barrageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.right.bottom.offset(0.0f);
- }];
-
- CGSize rankSize = CGSizeMake(21.0f, 18.0f);
- UIImageView *youpaipboardImgV = [[UIImageView alloc] init];
- [bgV addSubview:youpaipboardImgV];
- [youpaipboardImgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(5.0f);
- make.centerY.equalTo(bgV);
- make.size.mas_offset(rankSize);
- }];
-
- youpaipboardImgV.hidden = YES;
- CGFloat totalWidth = 0.0f;
- BOOL hasRank = NO;
- if (barrageAttachment.rankInfo != nil && [barrageAttachment.rankInfo.allKeys containsObject:@"img"]) {
- hasRank = YES;
- }
- if (hasRank) {
- youpaipboardImgV.hidden = NO;
- totalWidth = 7.0f + rankSize.width + 5.0f;
- [youpaipboardImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:barrageAttachment.rankInfo[@"img"]]];
- }
-
-
- /// 等级
- YOUPAILZLevelView *youpaiplevelView = [[YOUPAILZLevelView alloc] init];
- [bgV addSubview:youpaiplevelView];
- NSString *levelName = [barrageAttachment.gradeInfo objectForKey:@"grade_name"];
- NSInteger level = [[barrageAttachment.gradeInfo objectForKey:@"grade"] integerValue];
- NSString *levelIcon = [barrageAttachment.gradeInfo objectForKey:@"img1"];
- CGFloat levelIconWidth = [[barrageAttachment.gradeInfo objectForKey:@"icon_width"] floatValue];
- NSString *levelBg = [barrageAttachment.gradeInfo objectForKey:@"img2"];
- CGFloat levelBgWidth = [[barrageAttachment.gradeInfo objectForKey:@"icon1_width"] floatValue];
- [youpaiplevelView youpaifreloadWithIcon:levelIcon iconWidth:levelIconWidth bgImg:levelBg bgImgWidth:levelBgWidth levelName:levelName level:level];
- [youpaiplevelView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(youpaipboardImgV.mas_right).offset(5.0f);
- make.centerY.equalTo(bgV);
- make.size.mas_offset(youpaiplevelView.mj_size);
- }];
- totalWidth += youpaiplevelView.mj_w + 5.0f;
- UILabel *contentL = [[UILabel alloc] init];
- contentL.font = LCFont(13.0f);
- contentL.textColor = HexColorFromRGB(0xFFDD8D);
- [barrageView addSubview:contentL];
- [contentL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(totalWidth);
- make.top.bottom.offset(0.0f);
- make.right.offset(-7.0f);
- }];
-
- if (barrageAttachment.userInfo != nil && [barrageAttachment.userInfo.allKeys containsObject:@"nickname"]) {
- NSString *nickname = [barrageAttachment.userInfo objectForKey:@"nickname"];
- contentL.text = [NSString stringWithFormat:@"%@ 来了!",nickname];
- }
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObject:LCFont(13.5f) forKey:NSFontAttributeName];
- CGSize size = [contentL.text boundingRectWithSize:CGSizeMake(MAXFLOAT, 0.0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
- totalWidth = totalWidth + size.width + 7.0f;
- NSInteger heigth = KScreenHeight / 2;
- CGFloat y = arc4random() % heigth + heigth - 29.0f - SafeHeight;
- bgV.frame = CGRectMake(0.0f, y, totalWidth, 29.0f);
- [barrageView.layer addSublayer:[LCTools getGradientLayerWithSize:bgV.mj_size twoColors:@[[HexColorFromRGB(0xC55700) colorWithAlphaComponent:0.3f],[HexColorFromRGB(0xC55700) colorWithAlphaComponent:0.0f]] gradientType:GradientLeftToRight]];
- [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerBottomLeft View:bgV size:CGSizeMake(14.5f, 14.5f)];
-
- return bgV;
- }
- @end
|