7

NSMutableAttributedStringすべての属性をある属性から新しい属性にコピーしたいと思います。私が試したコードは次のとおりです。

[attrStr enumerateAttribute:NSFontAttributeName inRange:NSMakeRange(0, attrStr.length) options:0 usingBlock:^(id value, NSRange range, BOOL *stop) {
        if (value) {
           // UIFont *oldFont = (UIFont *)value;
            UIFont *newFont = [_label.attributedText
            [attrStr removeAttribute:NSFontAttributeName range:range];
            [attrStr addAttribute:NSFontAttributeName value:newFont range:range];
            //found = YES;
        }
    }];

コードは明らかに不完全であり、フォントに対してのみ実行しようとしているようです。NSMutableAttributedStringすべての属性をループして、新しい変数に追加したいと思います。NSMutableAttributedString更新:私の質問は、すべての属性を別の属性に適用するにはどうすればよいNSMutableAttributedStringですか? この方法を使用できますかsomehow:attribute:atIndex:effectiveRange

4

1 に答える 1