我需要創造這樣的事情。的iOS設置中的UILabel文本背景色(用圓角矩形)
其中一個方法是創建這樣的。我可以附加圖片(對於「PDF」)。
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;
但我不確定它是否好。有其他方法嗎?我可以突出顯示具有圓形背景的「PDF」字嗎?我可以使用屬性字符串輕鬆設置文本背景顏色,但不會有圓角。
你爲什麼不嘗試使用標籤的層??篩選label.layer.cornerRadius = 7的cornerRadius財產; –
您能否詳細闡述一下?我只有1個標籤,只需要更改'PDF'的背景顏色。 –
PDF是你的標籤吧? –