亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在UILabel中嵌入小圖標

如何在UILabel中嵌入小圖標

智慧大石 2019-12-09 14:00:59
我需要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;


查看完整回答
反對 回復 2019-12-09
  • 3 回答
  • 0 關注
  • 1034 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號