ios - 在 UILabel 之后放置一个 UIImage

标签 ios xcode interface-builder

我想要一个最大宽度为 100 的 UILabel,然后是一个 UIImage,我该如何在界面生成器中做到这一点?我希望如果文本较短,则标签小于 100,但 UIImage 就在标签后面。

最佳答案

您可以使用 iOS 7 中提供的 NSTextAttachment 类。无需使用框架。

NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
attachment.image = [UIImage imageNamed:@"image.png"];
NSAttributedString *attachmentAttrString = [NSAttributedString attributedStringWithAttachment:attachment];
NSMutableAttributedString *str= [[NSMutableAttributedString alloc] initWithString:@"hello"];
[str appendAttributedString:attachmentAttrString];
myLabel.attributedText = str;

关于ios - 在 UILabel 之后放置一个 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12968643/

相关文章:

ios - 在 Xcode 5 中将 iPhone NIB 转换为 iPad NIB

swift - UITableView 不会滚动到模糊 View 、选项卡栏或导航栏后面

ios - 在 IB 上调整 UIImage 大小的问题

ios - 数组为空时的错误处理

ios - 无法使用 Xcode 7.3.1 在我的 Swift 2 项目中使用 "po"检查变量 - 加载辅助函数时出错

arrays - 数组复制在 Swift 中显示 0 1 而不是 true false

Xcode 5 - 无法构建模块

ios - 如何在 Core Data iOS Swift 中插入具有抽象父对象的对象

ios - subview 添加到导航栏 ios

iphone - iPhone 应用程序的演练/工具提示/演示