MGGlobalVipView.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // MGGlobalVipView.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2020/6/18.
  6. // Copyright © 2020 xfg. All rights reserved.
  7. //
  8. #import "MGGlobalVipView.h"
  9. @implementation MGGlobalVipView
  10. - (instancetype)initWithFrame:(CGRect)frame
  11. {
  12. self = [super initWithFrame:frame];
  13. if (self) {
  14. [self setUpView];
  15. self.layer.masksToBounds = YES;
  16. self.layer.cornerRadius = frame.size.height / 2;
  17. }
  18. return self;
  19. }
  20. -(void)setUpView{
  21. self.backgroundColor = kClearColor;
  22. self.bgImgView = [[UIImageView alloc]initWithFrame:self.bounds];
  23. self.bgImgView.image = [UIImage imageNamed:@"mg_open_live_GlobalImg"];
  24. self.contentL = [UILabel new];
  25. self.contentL.frame = self.bounds;
  26. self.contentL.left = 65;
  27. self.contentL.textColor = [UIColor colorWithHexString:@"#844A15"];
  28. self.contentL.width = self.width - 65;
  29. self.contentL.font = [UIFont systemFontOfSize:15];
  30. self.iconImgView = [[UIImageView alloc]initWithFrame:CGRectMake(15, 4, 40, 32)];
  31. self.iconImgView.contentMode = UIViewContentModeScaleAspectFit;
  32. [self addSubview:self.bgImgView];
  33. [self addSubview:self.iconImgView];
  34. [self addSubview:self.contentL];
  35. }
  36. - (void)setModel:(CustomMessageModel *)model{
  37. _model = model;
  38. if (model.type == MSG_OPEN_VIP_TYPE) {
  39. [self.iconImgView sd_setImageWithURL:[NSURL URLWithString:model.noble_icon]];
  40. NSString *contentStr = [NSString stringWithFormat:ASLocalizedString(@"%@开通了%@贵族"),model.sender.nick_name,model.noble_name];
  41. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:contentStr];
  42. [attr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"ffffff"] range:NSMakeRange(0, model.sender.nick_name.length)];
  43. [attr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"ffffff"] range:NSMakeRange([NSString stringWithFormat:ASLocalizedString(@"%@开通了"),model.sender.nick_name].length, model.noble_name.length)];
  44. self.contentL.attributedText = attr;
  45. }else if(model.type == MSG_OPEN_GUARD_SUCCESS){
  46. // BogoGuardianModel *guardModel = [BogoGuardianModel modelWithDictionary:model.dicData];
  47. self.bgImgView.image = nil;
  48. self.backgroundColor = [[UIColor colorWithHexString:@"#9B00E0"]colorWithAlphaComponent:0.6];
  49. NSString *guardian_img = model.guardian_img;
  50. NSString *guardian_name = model.guardian_name;
  51. NSString *hostName = model.sender.host_nickname;
  52. [self.iconImgView sd_setImageWithURL:[NSURL URLWithString:guardian_img]];
  53. NSString *contentStr = [NSString stringWithFormat:ASLocalizedString(@"%@成为了%@的%@守护"),model.sender.nick_name,hostName,guardian_name];
  54. // [NSString stringWithFormat:@"%@开通了%@守护",model.sender.nick_name,guardian_name];
  55. self.contentL.textColor = kWhiteColor;
  56. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:contentStr];
  57. // [attr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#E9BD15"] range:NSMakeRange(model.sender.nick_name.length, ASLocalizedString(@"成为了").length)];
  58. // [attr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#E9BD15"] range:NSMakeRange(model.sender.nick_name.length + ASLocalizedString(@"成为了").length + hostName.length, @"的".length)];
  59. // [attr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#E9BD15"] range:NSMakeRange(contentStr.length - @"守护".length - guardian_name.length, @"守护".length + guardian_name.length)];
  60. self.contentL.attributedText = attr;
  61. CGSize wardListBtnSize = [contentStr textSizeIn:CGSizeMake(MAXFLOAT, MAXFLOAT) font:[UIFont systemFontOfSize:15]];
  62. self.contentL.width = wardListBtnSize.width;
  63. self.width = wardListBtnSize.width + 15 * 2 + 45;
  64. }
  65. else{
  66. self.contentL.text = [NSString stringWithFormat:@"%@ %@",model.sender.nick_name,model.sender.text];
  67. }
  68. }
  69. -(void)setAnnimateImage{
  70. NSMutableArray *arr = [NSMutableArray array];
  71. for (int i = 1; i < 14; i ++) {
  72. [arr addObject:[UIImage imageNamed:[NSString stringWithFormat:@"marquee_lucky_bg%d",i]]];
  73. }
  74. self.bgImgView.image = arr.firstObject;
  75. self.bgImgView.animationImages = arr;
  76. //动画的总时长(一组动画坐下来的时间 6张图片显示一遍的总时间)
  77. self.bgImgView.animationDuration = 2;
  78. self.bgImgView.animationRepeatCount = 0;//动画进行几次结束
  79. [self.bgImgView startAnimating];//开始动画
  80. // [imageView stopAnimating];//停止动画
  81. self.bgImgView.userInteractionEnabled = YES;
  82. }
  83. @end