Mic*_*ael 2 objective-c nstextattachment ios
我使用以下代码将RSS提要的原始HTML格式化为NSAttributedString.HTML包含的<img>标签可以将图像作为附件附加NSTextAttachment到NSAttributedString.问题是图像对于放置属性字符串的UITextView来说太大了.有没有办法可以在属性字符串中操纵图像的大小?以下是代表图像附件的整个属性字符串的摘录.
{
NSAttachment = "<NSTextAttachment: 0x16d29450> \"e0e1d483a922419807a2378a7ec031af.jpg\"";
NSColor = "UIDeviceRGBColorSpace 0 0 0 1";
NSFont = "<UICTFont: 0x16ef8a40> font-family: \"Times New Roman\"; font-weight: normal; font-style: normal; font-size: 12.00pt";
NSKern = 0;
NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 12, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n), DefaultTabInterval 36, Blocks (null), Lists (null), BaseWritingDirection 0, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0";
NSStrokeColor = "UIDeviceRGBColorSpace 0 0 0 1";
NSStrokeWidth = 0;
}
Run Code Online (Sandbox Code Playgroud)
小智 6
您可以迭代NSAttributedString,获取附件,边界并修改它们:
[myAtrrString enumerateAttribute:NSAttachmentAttributeName inRange:NSMakeRange(0, myAtrrString.length) options:0 usingBlock:^(id value, NSRange range, BOOL *stop) {
if (![value isKindOfClass:[NSTextAttachment class]]) {
return;
}
NSTextAttachment *attachment = (NSTextAttachment*)value;
CGRect bounds = attachment.bounds;
// modify bounds
attachment.bounds = bounds;
}];
Run Code Online (Sandbox Code Playgroud)