如何在UILabel中嵌入小图标

我需要UILabel在iOS7中嵌入一些小图标(自定义项目符号)。如何在界面设计器中执行此操作?或至少在代码中?

在Android中有leftDrawablerightDrawable用于标签,但是在iOS中如何实现?


智慧大石
浏览 944回答 3
3回答

holdtom

您可以使用iOS 7的文本附件(属于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;
打开App,查看更多内容
随时随地看视频慕课网APP