
ModelFrame.m
放大button的frameCGFloat textW = textSize.width + 40; CGFloat textH = textSize.height + 30;
// 计算消息正文的frame
// 1. 先计算正文的大小
CGSize textSize = [message.text sizeOfTextWithMaxSize:CGSizeMake(200, MAXFLOAT) font:textFont];
CGFloat textW = textSize.width + 40;
CGFloat textH = textSize.height + 30;
// 2. 再计算x,y
CGFloat textY = iconY;
CGFloat textX = message.type == CZMessageTypeOther ? CGRectGetMaxX(_iconFrame) : (screenW - margin - iconW - textW);
_textFrame = CGRectMake(textX, textY, textW, textH);
Model.m
添加内边距 btnText.contentEdgeInsets = UIEdgeInsetsMake(15, 20, 15, 20);
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
// 显示头像的UIImageView
UIImageView *imgViewIcon = [[UIImageView alloc] init];
[self.contentView addSubview:imgViewIcon];
self.imgViewIcon = imgViewIcon;
// 显示正文的按钮
UIButton *btnText = [[UIButton alloc] init];
// 设置正文的字体大小
btnText.titleLabel.font = textFont;
// 修改按钮的正文文字颜色
[btnText setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
// 设置按钮中的label的文字可以换行
btnText.titleLabel.numberOfLines = 0;
// 设置按钮的背景色
//btnText.backgroundColor = [UIColor purpleColor];
// 设置按钮中的titleLabel的背景色
//btnText.titleLabel.backgroundColor = [UIColor greenColor];
// 设置按钮的内边距
btnText.contentEdgeInsets = UIEdgeInsetsMake(15, 20, 15, 20);
[self.contentView addSubview:btnText];
self.btnText = btnText;
// 设置单元格的背景色为clearColor
self.backgroundColor = [UIColor clearColor];
return self;
}


网友评论