我需要UILabel在iOS7中嵌入一些小圖標(自定義項目符號)。如何在界面設計器中執行此操作?或至少在代碼中?在Android中有leftDrawable和rightDrawable用于標簽,但是在iOS中如何實現?
3 回答

holdtom
TA貢獻1805條經驗 獲得超10個贊
您可以使用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;
- 3 回答
- 0 關注
- 1034 瀏覽
添加回答
舉報
0/150
提交
取消