标签: tttattributedlabel

链接TTTAttributedLabel的点击颜色

我在我的项目中使用TTTAttributedLabel.我已经设法通过修改链接属性来更改我创建的任何链接的默认颜色和下划线.

NSArray *pKeys = [[NSArray alloc] initWithObjects:(id)kCTForegroundColorAttributeName,
                      (id)kCTUnderlineStyleAttributeName
                     , nil];

NSArray *pObjects = [[NSArray alloc] initWithObjects:pAlertColor,[NSNumber numberWithInt:
                                                                             kCTUnderlineStyleNone], nil];

NSDictionary *pLinkAttributes = [[NSDictionary alloc] initWithObjects:pObjects
                                                                  forKeys:pKeys];

self.alertMessage.linkAttributes = pLinkAttributes;
self.alertMessage.activeLinkAttributes = pLinkAttributes;
Run Code Online (Sandbox Code Playgroud)

但是,我注意到当我点击链接时,它会随着任何其他链接在点击时的瞬间变为红色.我需要改变这种颜色.有关如何做到这一点的任何线索?

objective-c ios tttattributedlabel

17
推荐指数
3
解决办法
1万
查看次数

在其超级视图中有一个UITapGestureRecognizer时,点击URL在TTTAttributedLabel中不起作用

有容器视图和UITapGestureRecognizer上面.它还有一个子视图TTTAttributedLabel.

当我从容器视图中删除手势识别器时,委托方法 TTTAttributedLabelDelegate

- (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url can be called.
Run Code Online (Sandbox Code Playgroud)

当我在容器视图上添加手势识别器时.只调用其action方法.委托方法TTTAttributedLabelDelegate不会被调用.

现在我需要在我点击链接时调用委托方法TTTAttributedLabel,并在我点击容器视图的其他区域时调用action方法.

谢谢.

objective-c ios uitapgesturerecognizer tttattributedlabel

16
推荐指数
2
解决办法
4550
查看次数

UILabel:自定义下划线颜色?

我需要a的文本UILabel是黑色的,但在文本下面有一个浅灰色的下划线.是否可以使用NSAttributedStringTTTAttributedLabel?或者是否需要使用Core Graphics的自定义绘图?

澄清:我需要一个不同颜色下划线的特定颜色文本.示例:红色下划线上的蓝色文本.

nsattributedstring uilabel ios ios7 tttattributedlabel

10
推荐指数
2
解决办法
1万
查看次数

如何在UILabel中使用UITextView检测并制作可点击链接

我正在构建一个聊天应用程序,出于性能原因,我需要使用UILabel而不是UITextView来显示聊天消息.我之前使用的是TextView,但滚动时的数据检测非常缓慢且不连贯.

问题是目前没有链接/电话/地址等... UILabels的检测.

如何知道字符串中存在链接或电话号码的位置,然后突出显示并使其在UILabel中可单击?

我已经阅读了很多关于如何为链接添加属性的文章,但是它们都是你知道范围或子串的链接.

我想获取任何字符串并找出是否包含链接以及这些链接的位置,然后将tapGestureRecognizer添加到标签并根据点击发生的位置执行操作.

我试图合并一个外部库(TTTAttributedLabel),但我正在使用swift,发现swift的文档有限.我确实设法导入库但是没有自动检测到链接.

uitextview uilabel datadetectortypes tttattributedlabel swift

9
推荐指数
1
解决办法
1万
查看次数

TTTAttributedLabel链接检测在iOS8中使用swift无法正常工作

我想使用TTTAttributedLabel来检测UITableViewCell标签中文本的链接,但它不起作用.我正在使用iOS8的swift.下面是UITableViewCell代码:

class StoryTableViewCell: UITableViewCell, TTTAttributedLabelDelegate {
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code

        // Link properties
        let textLabel = self.descriptionLabel
        let linkColor = UIColor(red: 0.203, green: 0.329, blue: 0.835, alpha: 1)
        let linkActiveColor = UIColor.blackColor()

        if (textLabel is TTTAttributedLabel) {
            var label = textLabel as TTTAttributedLabel
            label.linkAttributes = [NSForegroundColorAttributeName : linkColor]
            label.activeLinkAttributes = [NSForegroundColorAttributeName : linkActiveColor]        
            label.enabledTextCheckingTypes = NSTextCheckingType.Link.toRaw()

            label.delegate = self
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

uitableview ios tttattributedlabel swift ios8

8
推荐指数
1
解决办法
8895
查看次数

TTTAttributedLabel中的可点击链接与Swift

我想UILabel用一些带有可点击链接的文本制作一个.不是链接到网页,而是链接到像我这样做的行为UIButton.所以我用的TTTAttributedLabel是与之完美搭配的Objective C.现在我想做同样的事情Swift,所以我写了下面的代码:

self.someLabel.text = NSLocalizedString("Lost? Learn more.", comment: "")                
let range = self.someLabel.text!.rangeOfString(NSLocalizedString("Learn more", comment:""))        
self.someLabel.addLinkToURL (NSURL(string:"action://Learn more"), withRange:NSRange (range))
Run Code Online (Sandbox Code Playgroud)

但是,我无法使链接工作Swift.我收到错误:“Missing argument for parameter 'host' in call”最后一行.

ios tttattributedlabel swift

7
推荐指数
2
解决办法
8271
查看次数

TTTAttributedLabel链接正在设置样式但不可点击

我一直在研究获得可点击链接的解决方案.我可以在使用UITextView + NSAttributedString时使用它,但当它是UITableViewCell时它不会正确地自动布局.

现在我已经将TTTAttributedLabel添加到我的项目中,它完美地调整了视图的样式.链接也变为蓝色并加下划线.

但是点击它们什么都不做.我确实在我的控制器上实现了TTTAttributedLabelDelegate,在故事板中实现了标签实现MyLabel(它只是扩展了TTTAttributedLabel并具有委托选项,因为我希望它们在同一个函数中触发).现在我已经将控制器设置为我认为可能无法指向自身的委托.

但这些功能都没有被解雇,我得到了断点并登录了它.

我实现了didSelectLinkWithUrl和didLongPressLinkWithUrl.

 func attributedLabel(label: TTTAttributedLabel!, didSelectLinkWithURL url: NSURL!) {
        Debug.log("link clicked")
    }
    func attributedLabel(label: TTTAttributedLabel!, didLongPressLinkWithURL url: NSURL!, atPoint point: CGPoint) {
        Debug.log("link long clicked")
    }
Run Code Online (Sandbox Code Playgroud)

出口

@IBOutlet weak var content: MyLabel!
Run Code Online (Sandbox Code Playgroud)

MyLabel

导入UIKit导入TTTAttributedLabel

class MyLabel : TTTAttributedLabel, TTTAttributedLabelDelegate {

override func didMoveToSuperview() {
    if (self.delegate == nil) {
        self.delegate = self
    }
    self.enabledTextCheckingTypes = NSTextCheckingType.Link.rawValue
    self.userInteractionEnabled = true
}

func attributedLabel(label: TTTAttributedLabel!, didSelectLinkWithURL url: NSURL!) {
    Debug.log("link clicked")
}
func attributedLabel(label: TTTAttributedLabel!, didLongPressLinkWithURL url: …
Run Code Online (Sandbox Code Playgroud)

hyperlink ios tttattributedlabel swift

7
推荐指数
1
解决办法
5607
查看次数

在TTTAttributedLabel中指定多个/条件链接颜色

我在TTTAttributedLabel中添加了一个链接检测器,用于标识@mentions和#hashtags,并在我的TTTAttributedLabel实例中的该位置创建一个链接:

- (void)highlightMentionsInString:(NSString *)text withColor:(UIColor *)color isBold:(BOOL)bold isUnderlined:(BOOL)underlined
{
    NSRegularExpression *mentionExpression = [NSRegularExpression regularExpressionWithPattern:@"(?:^|\\s)(@\\w+)" options:NO error:nil];

    NSArray *matches = [mentionExpression matchesInString:text
                                                  options:0
                                                    range:NSMakeRange(0, [text length])];
    for (NSTextCheckingResult *match in matches) {
        NSRange matchRange = [match rangeAtIndex:1];
        NSString *mentionString = [text substringWithRange:matchRange];
        NSRange linkRange = [text rangeOfString:mentionString];
        NSString* user = [mentionString substringFromIndex:1];
        NSString* linkURLString = [NSString stringWithFormat:@"user:%@", user];
        [self.attributedLabel addLinkToURL:[NSURL URLWithString:linkURLString] withRange:linkRange];
    }
}
Run Code Online (Sandbox Code Playgroud)

我还发现我可以轻松更改链接颜色和属性:

NSArray *keys = [[NSArray alloc] initWithObjects:(id)kCTForegroundColorAttributeName,(id)kCTUnderlineStyleAttributeName
                             , nil];
NSArray *objects = [[NSArray alloc] initWithObjects:color,[NSNumber numberWithInt:kCTUnderlineStyleNone], nil]; …
Run Code Online (Sandbox Code Playgroud)

objective-c ios tttattributedlabel

6
推荐指数
1
解决办法
4521
查看次数

如何在TTTAttributedLabel中将HTML锚点设为可点击链接?

我有一个ios应用程序,它从服务器获取一段文本并将其显示在TTTAttributedLabel中.显示的文本将从HTML中删除.

例如

原始HTML

<p>
  Hello <a href="http://www.google.com">World!</a>
</p>
Run Code Online (Sandbox Code Playgroud)

文本显示在TTTAttributedLabel中

Hello World!
Run Code Online (Sandbox Code Playgroud)

但是,我想像HTML一样可以点击"世界"这个词.我知道TTTAttributedLabel可以像

TTTAttributedLabel *tttLabel = <# create the label here #>;
NSString *labelText = @"Hello World!";
tttLabel.text = labelText;
NSRange r = [labelText rangeOfString:@"World"]; 
[tttLabel addLinkToURL:[NSURL URLWithString:@"http://www.google.com"] withRange:r];
Run Code Online (Sandbox Code Playgroud)

但如果"世界"这个词在文本中出现不止一次,则上述代码将是错误的.

任何人都可以提出一个更好的方法来处理这种情况吗?谢谢

html iphone uilabel ios tttattributedlabel

4
推荐指数
1
解决办法
3356
查看次数

当UIAlertView呈现时,TTTAttributedLabel链接字体更改

我有一个奇怪的问题:我有一个带有链接的TTTAttributedLabel:

在此输入图像描述

"bryan"这个名字就是链接.当a UIAlertView通过此标签显示时,链接的字体会发生变化:

在此输入图像描述

如您所见,链接丢失了字体大小和重量.谁看过这个吗?"背景中的链接"或其他东西是否有单独的字体属性?谢谢.

nsattributedstring uialertview ios tttattributedlabel

4
推荐指数
1
解决办法
577
查看次数