Authored by 郁健超

修改弹幕cell UIreview by洛克

@@ -43,8 +43,8 @@ @@ -43,8 +43,8 @@
43 43
44 44
45 self.nameLabel.text = [NSString stringWithFormat:@" @%@已加入 ", name]; 45 self.nameLabel.text = [NSString stringWithFormat:@" @%@已加入 ", name];
46 -// CGFloat nameWidth = [self.nameLabel.text boundingRectWithSize:CGSizeMake(kUserNameWidth, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : kFontName} context:nil].size.width;  
47 -// [self.nameLabel setWidth:nameWidth]; 46 + CGFloat nameWidth = [self.nameLabel.text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 20) options:NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : kFontName} context:nil].size.width;
  47 + [self.nameLabel setWidth:nameWidth];
48 48
49 } 49 }
50 50
@@ -52,7 +52,7 @@ @@ -52,7 +52,7 @@
52 - (UILabel *)nameLabel 52 - (UILabel *)nameLabel
53 { 53 {
54 if (_nameLabel == nil) { 54 if (_nameLabel == nil) {
55 - _nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 6, 200, 20)]; 55 + _nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 6, kUserNameWidth, 20)];
56 [_nameLabel setFont:kFontName]; 56 [_nameLabel setFont:kFontName];
57 [_nameLabel setTextColor:[UIColor blackColor]]; 57 [_nameLabel setTextColor:[UIColor blackColor]];
58 [_nameLabel setTextAlignment:NSTextAlignmentLeft]; 58 [_nameLabel setTextAlignment:NSTextAlignmentLeft];
@@ -15,9 +15,9 @@ @@ -15,9 +15,9 @@
15 #define kContentMarginButtom 6 15 #define kContentMarginButtom 6
16 #define kMarginLeft 15 16 #define kMarginLeft 15
17 #define kMarginRight 15 17 #define kMarginRight 15
18 -#define kMarginTop 9  
19 -#define kMarginBottom 9  
20 -#define kPandingV 5 18 +#define kMarginTop 6
  19 +#define kMarginBottom 6
  20 +#define kPandingV 2
21 #define kPandingH 10 21 #define kPandingH 10
22 22
23 #define kUserAvatarWidth 35 23 #define kUserAvatarWidth 35
@@ -58,7 +58,7 @@ @@ -58,7 +58,7 @@
58 CGFloat nameHeight = [msg.userName boundingRectWithSize:CGSizeMake(kUserNameLableMaxWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : kFontUserName} context:nil].size.height; 58 CGFloat nameHeight = [msg.userName boundingRectWithSize:CGSizeMake(kUserNameLableMaxWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : kFontUserName} context:nil].size.height;
59 CGFloat msgHeight = [msg.message boundingRectWithSize:CGSizeMake(kUserNameLableMaxWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : kFontUserMsg} context:nil].size.height; 59 CGFloat msgHeight = [msg.message boundingRectWithSize:CGSizeMake(kUserNameLableMaxWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : kFontUserMsg} context:nil].size.height;
60 60
61 - [self.bgview setFrame:CGRectMake(kMarginLeft, kContentMarginTop, width - kMarginLeft - kMarginRight, cellHeight - kContentMarginTop-kContentMarginButtom)]; 61 + [self.bgview setFrame:CGRectMake(kMarginLeft, kContentMarginTop, width - kMarginLeft - kMarginRight, cellHeight - kContentMarginTop)];
62 [self.avatarImageView setFrame:CGRectMake(-1, 0, kUserAvatarWidth, CGRectGetHeight(self.bgview.frame))]; 62 [self.avatarImageView setFrame:CGRectMake(-1, 0, kUserAvatarWidth, CGRectGetHeight(self.bgview.frame))];
63 [self.nameLabel setFrame:CGRectMake(CGRectGetWidth(self.avatarImageView.frame)+kPandingH, kMarginTop, CGRectGetWidth(self.bgview.frame)-kUserAvatarWidth-2*kPandingH, nameHeight)]; 63 [self.nameLabel setFrame:CGRectMake(CGRectGetWidth(self.avatarImageView.frame)+kPandingH, kMarginTop, CGRectGetWidth(self.bgview.frame)-kUserAvatarWidth-2*kPandingH, nameHeight)];
64 [self.msgLabel setFrame:CGRectMake(CGRectGetWidth(self.avatarImageView.frame)+kPandingH, CGRectGetMaxY(self.nameLabel.frame)+kPandingV, CGRectGetWidth(self.bgview.frame)-kUserAvatarWidth-2*kPandingH, msgHeight)]; 64 [self.msgLabel setFrame:CGRectMake(CGRectGetWidth(self.avatarImageView.frame)+kPandingH, CGRectGetMaxY(self.nameLabel.frame)+kPandingV, CGRectGetWidth(self.bgview.frame)-kUserAvatarWidth-2*kPandingH, msgHeight)];
@@ -83,10 +83,10 @@ @@ -83,10 +83,10 @@
83 - (UIColor *)randomColor { 83 - (UIColor *)randomColor {
84 84
85 if (_randomColor == nil) { 85 if (_randomColor == nil) {
86 -// CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0  
87 -// CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white  
88 -// CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black  
89 -// _randomColor = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1]; 86 + // CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0
  87 + // CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white
  88 + // CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black
  89 + // _randomColor = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
90 NSString *colorHexStr = [self.colorArray objectAtIndex:arc4random() % [self.colorArray count]]; 90 NSString *colorHexStr = [self.colorArray objectAtIndex:arc4random() % [self.colorArray count]];
91 _randomColor = [UIColor colorWithHexString:colorHexStr]; 91 _randomColor = [UIColor colorWithHexString:colorHexStr];
92 92
@@ -125,7 +125,7 @@ @@ -125,7 +125,7 @@
125 125
126 + (CGFloat)cellHeightWithMessage:(YH_BarrageMsgModel *)msgModel 126 + (CGFloat)cellHeightWithMessage:(YH_BarrageMsgModel *)msgModel
127 { 127 {
128 - CGFloat cellHeight = kContentMarginTop + kMarginTop + kMarginBottom + kPandingV + kContentMarginButtom; 128 + CGFloat cellHeight = kContentMarginTop + kMarginTop + kMarginBottom + kPandingV;
129 129
130 cellHeight += [msgModel.userName boundingRectWithSize:CGSizeMake(kUserNameLableMaxWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : kFontUserName} context:nil].size.height; 130 cellHeight += [msgModel.userName boundingRectWithSize:CGSizeMake(kUserNameLableMaxWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : kFontUserName} context:nil].size.height;
131 131