我需要从NSMutableAttributedString中删除一些文本。
我的代码如下所示:
[attributedLabel setText:string afterInheritingLabelAttributesAndConfiguringWithBlock:^NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString)
{
NSRange stringRange = NSMakeRange(0, [mutableAttributedString length]);
NSRegularExpression *regexp = ParenthesisRegularExpression();
UIFont *italicSystemFont = [UIFont italicSystemFontOfSize:Size];
DLog(@"%@",italicSystemFont.fontName);
CTFontRef italicFont = CTFontCreateWithName((__bridge CFStringRef)italicSystemFont.fontName, italicSystemFont.pointSize, NULL);
[regexp enumerateMatchesInString:[mutableAttributedString string] options:0 range:stringRange usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
if (italicFont) {
[mutableAttributedString removeAttribute:(NSString *)kCTFontAttributeName range:result.range];
[mutableAttributedString addAttribute:(NSString *)kCTFontAttributeName value:(__bridge id)italicFont range:result.range];
CFRelease(italicFont);
}
}];
return mutableAttributedString;
}];
我想从此mutableAttributedString中删除括号。
试过这个:
[[attributedLabel.attributedText stringByReplacingOccurrencesOfString:@"(" withString:@""] stringByReplacingOccurrencesOfString:@")" withString:@""];
但是还有
no visible interface in NSAttributedString for stringByReplacingOccurrencesOfString.
如何从NSMutableAttributedString中删除文本?
最佳答案
为什么甚至假设NSMutableAttributedString
响应消息NSMutableString
响应?他们不会互相继承。相反,您应该阅读documentation并使用mutableString
方法来获取可变的字符串实例以进行操作。
关于ios - 如何从NSMutableAttributedString中删除文本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16799510/