修改KBChatUserMessageCell文字居中问题
This commit is contained in:
@@ -43,6 +43,7 @@
|
||||
self.messageLabel.numberOfLines = 0;
|
||||
self.messageLabel.font = [UIFont systemFontOfSize:16];
|
||||
self.messageLabel.textColor = [UIColor blackColor];
|
||||
self.messageLabel.textAlignment = NSTextAlignmentLeft;
|
||||
[self.bubbleView addSubview:self.messageLabel];
|
||||
|
||||
// 加载指示器
|
||||
@@ -76,6 +77,7 @@
|
||||
|
||||
- (void)configureWithMessage:(KBAiChatMessage *)message {
|
||||
self.messageLabel.text = message.text;
|
||||
[self updateMessageAlignmentForText:message.text];
|
||||
|
||||
if (message.isLoading) {
|
||||
self.bubbleView.hidden = YES;
|
||||
@@ -87,4 +89,24 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)updateMessageAlignmentForText:(NSString *)text {
|
||||
if (self.messageLabel.hidden || text.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ([text rangeOfString:@"\n"].location != NSNotFound) {
|
||||
self.messageLabel.textAlignment = NSTextAlignmentLeft;
|
||||
return;
|
||||
}
|
||||
|
||||
CGSize singleLineSize = [text sizeWithAttributes:@{NSFontAttributeName: self.messageLabel.font}];
|
||||
CGFloat minBubbleWidth = 50.0;
|
||||
CGFloat padding = 24.0;
|
||||
if (singleLineSize.width + padding <= minBubbleWidth + 0.5) {
|
||||
self.messageLabel.textAlignment = NSTextAlignmentCenter;
|
||||
} else {
|
||||
self.messageLabel.textAlignment = NSTextAlignmentLeft;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user