【发布时间】:2017-11-03 10:07:58
【问题描述】:
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]
initWithString:@"I have read, understand and agree to the following terms and conditions and web usage policy." attributes:nil];
NSRange conditionlinkRange = NSMakeRange(50,70);
// for the word "terms and conditions" in the string above
NSRange policylinkRange = NSMakeRange(75,92);
NSDictionary *linkAttributes = @{ NSForegroundColorAttributeName : [UIColor colorWithRed:0.05 green:0.4 blue:0.65 alpha:1.0],
NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle) };
[attributedString addAttributes:linkAttributes range:policylinkRange];
[attributedString addAttributes:linkAttributes range:conditionlinkRange];
应用程序在此行崩溃 [attributedString addAttributes:linkAttributes range:policylinkRange];
【问题讨论】:
-
请在您的问题中添加更多元素,仅在此处粘贴您的代码不会帮助用户识别您的问题。
-
我猜?
NSMakeRange(50,70)应该是NSMakeRange(50,20)。这是(location, length)不是(location, end)。其他范围也有同样的问题 -
谢谢,使用结束字符索引而不是长度
-
您的 Range 长度大于实际长度
标签: ios objective-c