Files
keyboard/keyBoard/Class/AiTalk/V/KBAICommentFooterView.m
2026-01-16 19:09:54 +08:00

122 lines
3.2 KiB
Objective-C

//
// 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 whiteColor];
[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 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, 4, 0, -4);
_actionButton.titleEdgeInsets = UIEdgeInsetsMake(0, -4, 0, 4);
[_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