无法使用tttattribedlabel框架



我正在使用TTTAttributedLabel制作UILabel超链接,我试图这样做以下操作:

 NSAttributedString *attString = [[NSAttributedString alloc] initWithString:@"By tapping you agree to the Terms of Use and Privacy Policy."
                attributes:@{
            (id)kCTForegroundColorAttributeName : (id)[UIColor redColor].CGColor,
                                                                                 NSFontAttributeName : [UIFont boldSystemFontOfSize:16],
                                                                                 NSKernAttributeName : [NSNull null],
                                                                                 (id)kTTTBackgroundFillColorAttributeName : (id)[UIColor greenColor].CGColor
                                                                                 }];
// The attributed string is directly set, without inheriting any other text
// properties of the label.
self.tttTermAndCondition.text = attString;
self.tttTermAndCondition.delegate = self; // Delegate methods are called when the user taps on a link (see `TTTAttributedLabelDelegate` protocol)
//self.tttTermAndCondition.text = @"Fork me on GitHub! (http://github.com/mattt/TTTAttributedLabel/)"; // Repository URL will be automatically detected and linked
self.tttTermAndCondition.enabledTextCheckingTypes = NSTextCheckingTypeLink;
NSRange range = [self.tttTermAndCondition.text rangeOfString:@"Terms of Use"];
[self.tttTermAndCondition addLinkToURL:[NSURL URLWithString:@"http://github.com/mattt/"] withRange:range];

这很好地显示了,但是当我单击使用期限时,

tttatributedlabel在其 - (nsarray *(链接方法中崩溃,它变成了僵尸对象。

我不知道我到底缺少什么。

预先感谢。

你好,我将您的代码放在我的示例应用程序中,它的工作正常,只需添加代表方法,而您的代码正常工作

- (void)viewDidLoad {
[super viewDidLoad];
tttTermAndCondition = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(0, 50, 320, 200)];
NSAttributedString *attString = [[NSAttributedString alloc] initWithString:@"By tapping you agree to the Terms of Use and Privacy Policy."
                                                                attributes:@{
                                                                             (id)kCTForegroundColorAttributeName : (id)[UIColor redColor].CGColor,
                                                                             NSFontAttributeName : [UIFont boldSystemFontOfSize:16],
                                                                             NSKernAttributeName : [NSNull null],
                                                                             (id)kTTTBackgroundFillColorAttributeName : (id)[UIColor greenColor].CGColor
                                                                             }];
// The attributed string is directly set, without inheriting any other text
// properties of the label.
tttTermAndCondition.text = attString;
tttTermAndCondition.delegate = self; // Delegate methods are called when the user taps on a link (see `TTTAttributedLabelDelegate` protocol)
//self.tttTermAndCondition.text = @"Fork me on GitHub! (http://github.com/mattt/TTTAttributedLabel/)"; // Repository URL will be automatically detected and linked
tttTermAndCondition.enabledTextCheckingTypes = NSTextCheckingTypeLink;
NSRange range = [tttTermAndCondition.text rangeOfString:@"Terms of Use"];
[tttTermAndCondition addLinkToURL:[NSURL URLWithString:@"http://github.com/mattt/"] withRange:range];
//self.se
[self.view addSubview:tttTermAndCondition];
// Do any additional setup after loading the view, typically from a nib.
}

-(void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url
{
    [[UIApplication sharedApplication] openURL:url options:nil completionHandler:nil];
}

相关内容

  • 没有找到相关文章

最新更新