Files
keyboard/CustomKeyboard/View/KBStreamTextView.h
2025-11-11 19:39:33 +08:00

54 lines
1.8 KiB
Objective-C
Raw Permalink 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.

//
// KBStreamTextView.h
// KeyBoard
//
// 一个可滚动的视图,用于接收“流式”文本输入。
// 当检测到分隔符(默认: "\t" 制表符)时,会将当前累计的文本作为一个段落
// 创建一个新的 UILabel每个标签支持自动换行和点击事件。
// 适用于流式数据逐步到达、按段落追加展示的场景。
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
typedef void (^KBStreamTextTapHandler)(NSInteger index, NSString *text);
@interface KBStreamTextView : UIView
/// 分段分隔符,默认 "\t"(制表符)。
@property (nonatomic, copy) NSString *delimiter;
/// 标签使用的字体,默认系统 16 号。
@property (nonatomic, strong) UIFont *labelFont;
/// 标签文本颜色iOS 13+ 默认 labelColor低版本默认黑色。
@property (nonatomic, strong) UIColor *labelTextColor;
/// 水平内边距(左右留白),默认 12。
@property (nonatomic, assign) CGFloat contentHorizontalPadding;
/// 标签间的垂直间距,默认 5。
@property (nonatomic, assign) CGFloat interItemSpacing;
/// 标签点击回调,提供被点击的序号与文本。
@property (nonatomic, copy, nullable) KBStreamTextTapHandler onLabelTap;
/// 是否裁剪各段落前后的空白/换行,默认 YES。
@property (nonatomic, assign) BOOL shouldTrimSegments;
/// 追加流式文本(边输边见):
/// - 实时将未完成段落展示在“当前标签”上;
/// - 当遇到分隔符时,先将当前标签视为“完成段”,可选裁剪空白,再创建一个新的空标签作为下一段的容器。
- (void)appendStreamText:(NSString *)text;
/// 清空所有标签并重置内部缓冲。
- (void)reset;
/// 结束输入:将当前正在输入的段落视为完成段(按需裁剪),但不会再新建标签。
- (void)finishStreaming;
@end
NS_ASSUME_NONNULL_END