1

昨日この質問を投稿しました: iOS の文字列から括弧を削除します。しかし、まだブラケットをラベルから取り外すことができません。

私の間違いがわからない。一晩かけて計算しましたが、まだできません。

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;
}

まだブラケットを取り外すことができません。誰かが私の間違いを指摘できますか? 本当に助けていただければ幸いです。

4

1 に答える 1