このようなものを作成する必要があります。道の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」の単語を強調表示できますか?私は簡単に属性の文字列でテキストの背景色を設定できますが、角が丸くなりません。
なぜラベルのレイヤーのcornerRadiusプロパティを使用しようとしないのですか?このようにlabel.layer.cornerRadius = 7; –
詳細を教えてください。私は1つのラベルしか持たず、「PDF」の背景色を変更する必要があります。 –
あなたのラベルはPDFですか? –