Coretext构成可点击的nsmutableattributedstring的一部分

时间:2012-11-02 00:31:21

标签: ios core-text nsattributedstring

假设我有一个CoreText NSMutableAttributedString,上面写着:“继续阅读”

我想让第一个单词“继续”可点击,以便我可以点击它并显示另一个UIView的负载。我已经找到了如何使其加下划线并将颜色更改为蓝色,但我怎样才能使其可链接。任何一个例子?

这是我的代码,使其加下划线,前景色为蓝色。

CFAttributedStringSetAttribute(string, CFRangeMake(0, 10),kCTForegroundColorAttributeName, [UIColor blueColor].CGColor);
          SInt32 type = kCTUnderlineStyleSingle;

CFNumberRef underline = CFNumberCreate(NULL, kCFNumberSInt32Type, &type);
CFAttributedStringSetAttribute(string, CFRangeMake(0, text.length),kCTUnderlineStyleAttributeName, underline);
CFAttributedStringSetAttribute(string, CFRangeMake(0, text.length),kCTUnderlineColorAttributeName, [UIColor blueColor].CGColor);

由于

1 个答案:

答案 0 :(得分:0)

那里有很多资源,其中一个就是 在这里找到Hyperlink in coretext

您需要做的是找到您想要点击的单词/部分的边界,并在处理点击的边界内添加子视图。希望它有所帮助!

相关问题