Files
keyboard/keyBoard/Class/AiTalk/V/KBAICommentFooterView.m
2026-01-28 13:43:36 +08:00

132 lines
3.6 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// KBAICommentFooterView.m
// keyBoard
//
// Created by Mac on 2026/1/16.
//
#import "KBAICommentFooterView.h"
#import "KBAICommentModel.h"
#import <Masonry/Masonry.h>
@interface KBAICommentFooterView ()
@property(nonatomic, strong) UIButton *actionButton;
@property(nonatomic, strong) UIView *lineView;
@end
@implementation KBAICommentFooterView
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithReuseIdentifier:reuseIdentifier];
if (self) {
[self setupUI];
}
return self;
}
#pragma mark - UI Setup
- (void)setupUI {
self.contentView.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:self.actionButton];
[self.contentView addSubview:self.lineView];
[self.actionButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(68); // 对齐二级评论
make.centerY.equalTo(self.contentView);
make.height.mas_equalTo(24);
}];
[self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(16);
make.right.equalTo(self.contentView).offset(-16);
make.bottom.equalTo(self.contentView);
make.height.mas_equalTo(0.5);
}];
}
#pragma mark - Configuration
- (void)configureWithComment:(KBAICommentModel *)comment {
KBAIReplyFooterState state = [comment footerState];
NSString *title = @"";
switch (state) {
case KBAIReplyFooterStateHidden: {
self.actionButton.hidden = YES;
break;
}
case KBAIReplyFooterStateExpand: {
self.actionButton.hidden = NO;
title = [NSString
stringWithFormat:@"展开%ld条回复", (long)comment.totalReplyCount];
[self.actionButton setImage:[UIImage systemImageNamed:@"chevron.down"]
forState:UIControlStateNormal];
break;
}
case KBAIReplyFooterStateLoadMore: {
self.actionButton.hidden = NO;
NSInteger remaining =
comment.totalReplyCount - comment.displayedReplies.count;
title =
[NSString stringWithFormat:@"展开更多回复(%ld条", (long)remaining];
[self.actionButton setImage:[UIImage systemImageNamed:@"chevron.down"]
forState:UIControlStateNormal];
break;
}
case KBAIReplyFooterStateCollapse: {
self.actionButton.hidden = NO;
title = @"收起";
[self.actionButton setImage:[UIImage systemImageNamed:@"chevron.up"]
forState:UIControlStateNormal];
break;
}
}
[self.actionButton setTitle:title forState:UIControlStateNormal];
}
#pragma mark - Actions
- (void)actionButtonTapped {
if (self.onAction) {
self.onAction();
}
}
#pragma mark - Lazy Loading
- (UIButton *)actionButton {
if (!_actionButton) {
_actionButton = [UIButton buttonWithType:UIButtonTypeCustom];
_actionButton.titleLabel.font = [UIFont systemFontOfSize:13];
[_actionButton setTitleColor:[UIColor secondaryLabelColor]
forState:UIControlStateNormal];
_actionButton.tintColor = [UIColor secondaryLabelColor];
// 文字在左,图标在右
_actionButton.semanticContentAttribute =
UISemanticContentAttributeForceLeftToRight;
_actionButton.imageEdgeInsets = UIEdgeInsetsMake(0, -2, 0, 2);
_actionButton.titleEdgeInsets = UIEdgeInsetsMake(0, 2, 0, -2);
[_actionButton addTarget:self
action:@selector(actionButtonTapped)
forControlEvents:UIControlEventTouchUpInside];
}
return _actionButton;
}
- (UIView *)lineView {
if (!_lineView) {
_lineView = [[UIView alloc] init];
_lineView.backgroundColor = [UIColor separatorColor];
}
return _lineView;
}
@end