我想要一个最大宽度为 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/