Authored by 郁健超

修改弹幕cell UIreview by洛克

... ... @@ -43,16 +43,16 @@
self.nameLabel.text = [NSString stringWithFormat:@" @%@已加入 ", name];
// CGFloat nameWidth = [self.nameLabel.text boundingRectWithSize:CGSizeMake(kUserNameWidth, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : kFontName} context:nil].size.width;
// [self.nameLabel setWidth:nameWidth];
CGFloat nameWidth = [self.nameLabel.text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 20) options:NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : kFontName} context:nil].size.width;
[self.nameLabel setWidth:nameWidth];
}
- (UILabel *)nameLabel
{
if (_nameLabel == nil) {
_nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 6, 200, 20)];
_nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 6, kUserNameWidth, 20)];
[_nameLabel setFont:kFontName];
[_nameLabel setTextColor:[UIColor blackColor]];
[_nameLabel setTextAlignment:NSTextAlignmentLeft];
... ...
... ... @@ -15,9 +15,9 @@
#define kContentMarginButtom 6
#define kMarginLeft 15
#define kMarginRight 15
#define kMarginTop 9
#define kMarginBottom 9
#define kPandingV 5
#define kMarginTop 6
#define kMarginBottom 6
#define kPandingV 2
#define kPandingH 10
#define kUserAvatarWidth 35
... ... @@ -58,7 +58,7 @@
CGFloat nameHeight = [msg.userName boundingRectWithSize:CGSizeMake(kUserNameLableMaxWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : kFontUserName} context:nil].size.height;
CGFloat msgHeight = [msg.message boundingRectWithSize:CGSizeMake(kUserNameLableMaxWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : kFontUserMsg} context:nil].size.height;
[self.bgview setFrame:CGRectMake(kMarginLeft, kContentMarginTop, width - kMarginLeft - kMarginRight, cellHeight - kContentMarginTop-kContentMarginButtom)];
[self.bgview setFrame:CGRectMake(kMarginLeft, kContentMarginTop, width - kMarginLeft - kMarginRight, cellHeight - kContentMarginTop)];
[self.avatarImageView setFrame:CGRectMake(-1, 0, kUserAvatarWidth, CGRectGetHeight(self.bgview.frame))];
[self.nameLabel setFrame:CGRectMake(CGRectGetWidth(self.avatarImageView.frame)+kPandingH, kMarginTop, CGRectGetWidth(self.bgview.frame)-kUserAvatarWidth-2*kPandingH, nameHeight)];
[self.msgLabel setFrame:CGRectMake(CGRectGetWidth(self.avatarImageView.frame)+kPandingH, CGRectGetMaxY(self.nameLabel.frame)+kPandingV, CGRectGetWidth(self.bgview.frame)-kUserAvatarWidth-2*kPandingH, msgHeight)];
... ... @@ -73,7 +73,7 @@
totalHeight += 33; // margins
return CGSizeMake(size.width, totalHeight);
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
... ... @@ -83,13 +83,13 @@
- (UIColor *)randomColor {
if (_randomColor == nil) {
// CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0
// CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white
// CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black
// _randomColor = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
// CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0
// CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white
// CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black
// _randomColor = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
NSString *colorHexStr = [self.colorArray objectAtIndex:arc4random() % [self.colorArray count]];
_randomColor = [UIColor colorWithHexString:colorHexStr];
}
return _randomColor;
... ... @@ -102,20 +102,20 @@
[self reLayoutCellWithWidth:width msg:msgModel];
[self.avatarImageView sd_setImageWithURL:msgModel.avatar placeholderImage:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
if (image) {
[weakSelf.avatarImageView setBackgroundColor:[UIColor whiteColor]];
}
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:weakSelf.avatarImageView.bounds
byRoundingCorners:(UIRectCornerBottomLeft|UIRectCornerTopLeft)
cornerRadii:CGSizeMake(6.0, 6.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = weakSelf.bgview.bounds;
maskLayer.path = maskPath.CGPath;
weakSelf.avatarImageView.layer.mask = maskLayer;
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:weakSelf.avatarImageView.bounds
byRoundingCorners:(UIRectCornerBottomLeft|UIRectCornerTopLeft)
cornerRadii:CGSizeMake(6.0, 6.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = weakSelf.bgview.bounds;
maskLayer.path = maskPath.CGPath;
weakSelf.avatarImageView.layer.mask = maskLayer;
}];
[self.nameLabel setText:[NSString stringWithFormat:@"@%@", msgModel.userName]];
... ... @@ -125,11 +125,11 @@
+ (CGFloat)cellHeightWithMessage:(YH_BarrageMsgModel *)msgModel
{
CGFloat cellHeight = kContentMarginTop + kMarginTop + kMarginBottom + kPandingV + kContentMarginButtom;
CGFloat cellHeight = kContentMarginTop + kMarginTop + kMarginBottom + kPandingV;
cellHeight += [msgModel.userName boundingRectWithSize:CGSizeMake(kUserNameLableMaxWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : kFontUserName} context:nil].size.height;
cellHeight += [msgModel.userName boundingRectWithSize:CGSizeMake(kUserNameLableMaxWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : kFontUserName} context:nil].size.height;
cellHeight += [msgModel.message boundingRectWithSize:CGSizeMake(kUserNameLableMaxWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : kFontUserMsg} context:nil].size.height;
cellHeight += [msgModel.message boundingRectWithSize:CGSizeMake(kUserNameLableMaxWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : kFontUserMsg} context:nil].size.height;
return cellHeight;
... ...