我有一个 NSAttributedString,我要向其中添加一个 NSTextAttachment。该图像为 50w x 50h,但我希望它缩小以反映属性字符串的行高。我以为这会自动完成,但我想不会。我查看了 UImage 类参考,但该图像似乎没有在 UIImageView 中设置,因此无法访问框架属性。这是我目前拥有的屏幕截图:
在理想的情况下,我还想实现一种根据用户输入(例如增加字体大小)来放大图像的方法。关于如何实现这一目标有什么想法吗?
thx
edit 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];
您应该设置边界表单附件来调整图像大小,如下所示:
attachment.bounds = CGRectMake(0, 0, yourImgWidth, yourImgHeight)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)