j2e*_*nue 7 ios nsmutableattributedstring
我想将所有属性从一个复制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;
}
}];
Run Code Online (Sandbox Code Playgroud)
代码显然是不完整的,看起来它试图只为字体做.我想遍历每个属性并将其添加到一个新NSMutableAttributedString变量中.更新:我的问题是如何将一个属性NSMutableAttributedString应用于另一个属性NSMutableAttributedString?我们可以使用这种方法吗?somehow:attribute:atIndex:effectiveRange
Dim*_*ima -3
NSMutableAttributedString( 和NSAttributedString) 符合NSCopying. 所以你应该能够这样做:
NSMutableAttributedString *mutableCopy = attrStr.mutableCopy;
NSAttributedString *immutableCopy = attrStr.copy;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1303 次 |
| 最近记录: |