我需要在 iOS7 中的 UILabel
中嵌入小图标(某种自定义项目符号)。
我如何在界面设计器中做到这一点?或者至少在代码中?
在Android中,标签有leftDrawable
和rightDrawable
,但是在iOS中是如何实现的呢?
安卓示例:
最佳答案
您可以使用 iOS 7 的 text attachments 执行此操作,它们是 TextKit 的一部分。一些示例代码:
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
attachment.image = [UIImage imageNamed:@"MyIcon.png"];
NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
NSMutableAttributedString *myString= [[NSMutableAttributedString alloc] initWithString:@"My label text"];
[myString appendAttributedString:attachmentString];
myLabel.attributedText = myString;
https://stackoverflow.com/questions/19318421/