Dav*_*son 5 split ios nsmutableattributedstring
有没有一种简单的方法来拆分a,NSAttributedString以便我仅获得最后 50条左右的行?
NSMutableAttributedString *resultString = [receiveView.attributedText mutableCopy];
[resultString appendAttributedString:[ansiEscapeHelper attributedStringWithANSIEscapedString:message]];
if ([[resultString.string componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] count]>50) {
//resultString = [resultString getLastFiftyLines];
}
Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法来分割 NSAttributedString 这样我只得到最后 50 行左右?
不可以。您必须请求string并确定您感兴趣的范围,然后NSAttributedString使用 API 创建从源派生的新表示,例如- [NSAttributedString attributedSubstringFromRange:]:
- (NSAttributedString *)lastFiftyLinesOfAttributedString:(NSAttributedString *)pInput
{
NSString * string = pInput.string;
NSRange rangeOfInterest = ...determine the last 50 lines in "string"...;
return [pInput attributedSubstringFromRange:rangeOfInterest];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4092 次 |
| 最近记录: |