昨天我发布了这个问题:Removing parentheses from the string in iOS。但是我仍然无法从标签中删除括号。在iOS中删除UILabel中的支架
不知道我的错误。花了整整一个晚上,仍然无法这样做。
我正在使用TTTAttributedLabel。我的代码如下所示:
-(TTTAttributedLabel*)setItalicTextForLabel:(TTTAttributedLabel*)attributedLabel fontSize:(float)Size
{
[attributedLabel setText:[self.infoDictionary objectForKey:@"description"] 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;
}];
[[attributedLabel.text stringByReplacingOccurrencesOfString:@"[" withString:@""] stringByReplacingOccurrencesOfString:@"]" withString:@""];
return attributedLabel;
}
仍然无法删除括号。任何人都可以指出我的错误吗?真的很感激帮助。
我想你指的支架,你试图删除这个字符, “[” 右 – aaronman
说错误的话。编辑了这个问题。 – lakesh
我看到你正在尝试做什么。我所做的是修改'MGMushParser'(GitHub上的一个库)来获得我想要的结果。它会解析某些“标签”(在你的案例中是[italic text]),并用一些属性替换它。 – borrrden