测试已测试 | ✓ |
Lang语言 | Obj-CObjective C |
许可证 | MIT |
释放最后发布 | 2015年7月 |
由 Seb C. Thiebaud,David Whetstone 维护。
一个为 iOS 定制的 UILabel,其中某些单词可点击,如 Twitter(#话题、@用户和链接)。
请使用 CocoaPods 并将 STTweetLabel 包含在您的 Podfile 中。
重要提示:STTweetLabel 3.0 基于 TextKit,并且仅与 iOS 7 及以上版本兼容。
在 Xcode 中构建并运行 STTweetLabelExample 项目,以查看 STTweetLabel
的实际应用。
STTweetLabel *tweetLabel = [[STTweetLabel alloc] initWithFrame:CGRectMake(10.0, 60.0, 300.0, 160.0)];
[tweetLabel setText:@"Hi. This is a new tool for @you! Developed by @SebThiebaud for #iPhone #ObjC... and #iOS7 ;-) My GitHub page: https://#/pQXDoiYA"];
[self.view addSubview:tweetLabel];
不要忘记实现 detectionBlock
。如果没有实现此 block,将无法检测是否有人点击了话题、用户名或链接。Blocks 很简单。您只需添加几行代码
[tweetLabel setDetectionBlock:^(STTweetHotWord hotWord, NSString *string, NSString *protocol, NSRange range) {
// Do something
}];
NSString *text
:要显示的文本。NSArray *validProtocols
:所有有效的链接协议(默认:@[@"http", @"https"]
)。BOOL leftToRight
:书写方向(默认:YES
)。BOOL textSelectable
:允许用户选择文本(默认:YES
)。UIColor *selectionColor
:如果启用了 BOOL textSelectable
,则为选择背景的颜色(默认:[UIColor colorWithWhite:0.9 alpha:1.0]
)。NSTextAlignment textAlignment
:文本对齐(默认:NSTextAlignmentLeft
)。以下两个方法刷新组件。这意味着您应在初始化 STTweetLabel 实例时设置属性。
-[STTweetLabel setAttributes:(NSDictionary *)attributes]
:所有文本的属性字典。-[STTweetLabel setAttributes:(NSDictionary *)attributes hotWord:(STTweetHotWord)hotWord]
:特定 STTweetHotWord 的属性字典。-[STTweetLabel suggestedFrameSizeToFitEntireStringConstraintedToWidth:(CGFloat)width]
:返回对于提交的文本计算出的 CGSize。灵感来源于原始的 Twitter 应用程序。
Sebastien Thiebaud
STTweetLabel 可在 MIT 许可下使用。