ios - 如何在标签文本之间包含 png 图像

标签 ios objective-c xcode uilabel

我想在我的标签文本之间包含 png 图像。如何在 objective-c 中进行处理。

最佳答案

如果有人觉得有用,这是答案----->

 NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
    attachment.image = [UIImage imageNamed:@"Attach-52.png"];

    NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];

    NSMutableAttributedString *myString= [[NSMutableAttributedString alloc] initWithString:@"My label text"];
    [myString appendAttributedString:attachmentString];

    myLabel.attributedText = myString;

同样,您可以通过 NSAttributedString 添加 png 图像。

关于ios - 如何在标签文本之间包含 png 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36996682/

相关文章:

ios - 以编程方式分配接口(interface)对象会影响加载时间吗?

ios - 在 Swift/XCode 8 中从 subview 更改父 View ?

ios - 将代码从基于页面的应用程序传输到基于选项卡的应用程序时应用程序崩溃 (iOS)

ios - 将数组传递给新的 ViewController 时出现 EXC_BAD_ACCESS

iphone - 在 App Store 中验证应用程序 - 初学者

iphone - 无法在基本单元测试设置中测试我的类(class)

ios - 如何创建像联系人应用程序中那样的可收缩索引栏?

objective-c - NSPredicate 计数 NSString 的数量

c++ - 如何在 OSX Mavericks 中为 Xcode 5.0.2 安装命令行工具?

objective-c - NSURLConnection 成功后重新加载 TableView