MSPTouchableLabel 是一个 UILabel 子类,它提供类似于 UITableView 的界面来创建可交互的标签。没有依赖项。
由于尚未达到 1.0.0 版本,此 pod 的公共 API 可能会更改。升级时请谨慎使用。不建议在生产应用中使用。
将 pod 'MSPTouchableLabel'
添加到您的 Podfile 并运行 pod install
或 pod update
。
最基本的用法
MSPTouchableLabelDataSource
方法 textForTouchableLabel:
。您可选地实现 MSPTouchableLabelDelegate 方法来了解对标签的交互,如下所示
#import "MSPTouchableLabel.h"
@interface BasicUsageViewController()<MSPTouchableLabelDataSource, MSPTouchableLabelDelegate>
@property (nonatomic, strong) NSNumber* tapCount;
@end
@implementation BasicUsageViewController
- (void)viewDidLoad {
[super viewDidLoad];
MSPTouchableLabel* touchableLabel = [[MSPTouchableLabel alloc] init];
touchableLabel.dataSource = self;
touchableLabel.delegate = self;
touchableLabel.frame = CGRectMake(20, 20, 200, 200);
[self.view addSubview:touchableLabel];
self.tapCount = @0;
}
- (NSArray*)textForTouchableLabel:(MSPTouchableLabel*)touchableLabel {
return @[@"You have ", @"tapped", @" the verb in this sentence ", self.tapCount.stringValue, @" times."];
}
- (void)touchableLabel:(MSPTouchableLabel*)touchableLabel touchesDidEndAtIndex:(NSInteger)index {
if (index == 1) { // index of the verb, "tapped"
self.tapCount = @(self.tapCount.intValue + 1);
}
}
@end
对于更大的示例,请克隆此存储库并查看 Examples 目录。运行项目以便看到它们的效果(或查看此文档底部的 .gifs)。
MIT
在点击时替换文本
链接
Madlibs
突出显示