【发布时间】:2014-03-12 16:02:21
【问题描述】:
我有一个 NSAttributedString,我正在向其中添加一个 NSTextAttachment。该图像是 50w x 50h,但我希望它按比例缩小以反映属性字符串的行高。我以为这会自动完成,但我想不会。我查看了 UImage 类参考,但该图像似乎没有在 UIImageView 中设置,因此无法访问框架属性。这是我目前拥有的屏幕截图:
在理想情况下,我还想实现一种根据用户输入放大图像的方法(例如增加字体大小)。关于如何实现这一点的任何想法?
谢谢
编辑 1
我是这样创建它的:
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
textAttachment.image = [UIImage imageNamed:@"note-small.png"];
NSLog(@"here is the scale: %f", textAttachment.image.scale);
NSAttributedString *attrStringWithImage = [NSAttributedString attributedStringWithAttachment:textAttachment];
[headerAS replaceCharactersInRange:NSMakeRange([headerAS length], 0) withString:@" "];
[headerAS replaceCharactersInRange:NSMakeRange([headerAS length], 0) withAttributedString:attrStringWithImage];
【问题讨论】:
标签: ios ios7 uiimage nsattributedstring nstextattachment