iOS 8设备上未显示NSTextAttachment图像(使用iOS7.1 sdk) [英] NSTextAttachment image not displayed on iOS 8 devices (with iOS7.1 sdk)

查看:134
本文介绍了iOS 8设备上未显示NSTextAttachment图像(使用iOS7.1 sdk)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在几个iOS 8设备上构建了我的项目,其中baseSDK设置为iOS 7.1。
不幸的是,作为属性添加到NSMutableAttributedString的相关实例的所有NSTextAttachment图像都隐藏在iOS 8设备和iOS 8模拟器上(它们仍然在具有7.1和iOS 7.1模拟器的设备上可见)。这些字符串在其超视图中的框架设置为好像图像在那里,但图像本身不可见或呈现。

I have just built my project on several iOS 8 devices with baseSDK set to iOS 7.1. Unfortunately, all NSTextAttachment images added as attributes to relevant instances of NSMutableAttributedString are hidden on iOS 8 devices and the iOS 8 simulator (they are still visible on devices with 7.1 and the iOS 7.1 simulator). The frame for these strings within their superviews is set as if the image was there, but the image itself is just not visible or rendered.

是否有其他人遇到过没有出现在iOS 8上的文本附件问题。如果有,是否有解决方法?如果没有,我的代码是否有问题(粘贴在下面)?这个实例特别为UIButton设置了一个属性标题,但我有其他实例的附件是显示相同行为的简单UILabel。

Has anybody else ran into the issue of text attachments not appearing on iOS 8. If so, is there a workaround? If not, is there something wrong with my code (pasted below)? This instance in particular sets an attributed title for a UIButton, but I have other instances with attachments that are simple UILabels that are displaying the same behavior.

NSMutableAttributedString *attrButtonTitle = [[NSMutableAttributedString alloc] initWithString:@"Let's go!"];
NSTextAttachment *doubleArrowIcon = [[NSTextAttachment alloc] initWithData:nil ofType:nil];
doubleArrowIcon.image = [UIImage imageNamed:@"double-arrows"];
[attrButtonTitle appendAttributedString:[[NSAttributedString alloc] initWithString:@"  " attributes:@{NSAttachmentAttributeName : doubleArrowIcon, NSBaselineOffsetAttributeName : @(-2)}]];
[self.nextButton setAttributedTitle:attrButtonTitle forState:UIControlStateNormal];

注意:我会发布图片以说明我是否可以,但我没有最小的堆栈溢出这样做的声誉。

Note: I would post images to illustrate if I could, but I do not have the minimum stack overflow reputation to do so.

推荐答案

我仍然不确定为什么上面的代码在使用以下代码编译时不会在iOS8设备上显示图像7.1 SDK,但我找到了一种解决方法。我尝试了具有文本附件的NSMutableAttributedString的不同初始化方法,直到我得到了完成工作的东西。代码如下:

I'm still unsure why the above code does not display images on iOS8 devices when compiled with the 7.1 SDK, but I have found a workaround. I tried out different initialization methods for NSMutableAttributedString that has a text attachment until I got something that did the job. Code below:

NSTextAttachment *doubleArrowIcon = [[NSTextAttachment alloc] initWithData:nil ofType:nil];
doubleArrowIcon.image = [UIImage imageNamed:@"double-arrows"];

NSAttributedString *textAttachment = [NSAttributedString attributedStringWithAttachment:doubleArrowIcon];

NSMutableAttributedString *mutableTextAttachment = [[NSMutableAttributedString alloc] initWithAttributedString:textAttachment];
[mutableTextAttachment addAttribute:NSBaselineOffsetAttributeName value:[NSNumber numberWithInt:-2] range:NSMakeRange(0, [textAttachment length])  ];
[attrButtonTitle appendAttributedString:mutableTextAttachment];

这篇关于iOS 8设备上未显示NSTextAttachment图像(使用iOS7.1 sdk)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆