我需要UILabel在iOS7中嵌入一些小圖標(biāo)(自定義項(xiàng)目符號(hào))。如何在界面設(shè)計(jì)器中執(zhí)行此操作?或至少在代碼中?在Android中有l(wèi)eftDrawable和rightDrawable用于標(biāo)簽,但是在iOS中如何實(shí)現(xiàn)?
3 回答

holdtom
TA貢獻(xiàn)1805條經(jīng)驗(yàn) 獲得超10個(gè)贊
您可以使用iOS 7的文本附件(屬于TextKit的一部分)來(lái)執(zhí)行此操作。一些示例代碼:
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 關(guān)注
- 1033 瀏覽
添加回答
舉報(bào)
0/150
提交
取消