Ios NSTextAttachment未显示在今日通知中心小部件中
我有一个通知中心小部件,它有一个带有表视图单元格的表视图。在单元格中,我有一个标签,我想显示文本+图像。作为NSTextAttachment包含的图像。我在应用程序中有以下代码:Ios NSTextAttachment未显示在今日通知中心小部件中,ios,objective-c,ios8,ios8-today-widget,Ios,Objective C,Ios8,Ios8 Today Widget,我有一个通知中心小部件,它有一个带有表视图单元格的表视图。在单元格中,我有一个标签,我想显示文本+图像。作为NSTextAttachment包含的图像。我在应用程序中有以下代码: NSTextAttachment *attachment = [NSTextAttachment new]; attachment.image = [UIImage imageWithData:item.image]; NSAttributedString *itemImage = [NSAttributedStrin
NSTextAttachment *attachment = [NSTextAttachment new];
attachment.image = [UIImage imageWithData:item.image];
NSAttributedString *itemImage = [NSAttributedString attributedStringWithAttachment:attachment];
NSAttributedString *itemName = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@", item.name]];
NSMutableAttributedString *itemString = [[NSMutableAttributedString alloc] initWithAttributedString:itemImage];
[itemString appendAttributedString:itemName];
cell.nameLabel.attributedText = itemString;
这段代码在应用程序内部工作,但我也尝试在我的小部件中使用(因此今天是ViewController)。当显示在小部件中时,标签上不会显示任何图像。如果在运行此代码时停止,我可以看到attachment.image设置正确。我做错了什么?谢谢 试试换衣服
NSTextAttachment *attachment = [NSTextAttachment new];
到
这可能与本文中的问题相同:在我设置了
cell.namelab.attributeText=itemString之后,它出现了代码>我后来设置了cell.namelab.text=itemString,因此它覆盖了属性字符串,不幸的是没有任何区别
NSTextAttachment *attachment = [NSTextAttachment alloc] initWithData:nil ofType:nil];