MSPTouchableLabel 0.5.0

MSPTouchableLabel 0.5.0

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
Released最后发布2016年1月

Michael Pace 维护。




  • 作者
  • Michael Pace

build status

MSPTouchableLabel 是一个 UILabel 子类,它提供类似于 UITableView 的界面来创建可交互的标签。没有依赖项。

由于尚未达到 1.0.0 版本,此 pod 的公共 API 可能会更改。升级时请谨慎使用。不建议在生产应用中使用。

安装

pod 'MSPTouchableLabel' 添加到您的 Podfile 并运行 pod installpod update

使用

最基本的用法

  • 实例化一个 MSPTouchableLabel。
  • 设置标签的数据源。
  • 实现 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)。

贡献

  1. Fork 此存储库并进行您的更改。
  2. 编写一个测试用例以说明您错误修正或功能的意图并证明它按预期工作。
  3. 发送拉取请求😁。我将尽力及时回应。

许可证

MIT

另请参阅

一些示例应用

在点击时替换文本

replace text

链接

links

Madlibs

mad libs

突出显示

highlighting