La chaîne est juste une donnée au format texte, ce n'est pas visuel. Vous avez besoin d'étiquettes, ce sont des étiquettes là-bas. Et puis placez votre chaîne à cette étiquette.
let label = UILabel()
label.backgroundColor = .green
label.text = "Label" // You set your string to your label
label.layer.cornerRadius = 5
label.layer.borderColor = .clear
label.layer.borderWidth = 1
Le code ci-dessus crée une étiquette et définit tout ce dont vous avez besoin pour l'obtenir comme dans l'image. Vous devez maintenant ajouter cette étiquette à votre vue ou vous pouvez définir ces propriétés sur une étiquette existante.
EDIT:
Si vous voulez faire du texte individuel à l'intérieur d'une vue de texte coloré, vous pouvez utiliser TTTAttributedLabel et définir un texte attribué à fond en morceaux individuels de texte.
Vous pouvez trouver TTTAttributedLabel here.
CornerRadius:kTTTBackgroundCornerRadiusAttributeName
BackgroundColor:kTTTBackgroundFillColorAttributeName
Exemple d'utilisation:
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithAttributedString:TTTAttributedTestString()];
[string addAttribute:kTTTBackgroundFillColorAttributeName value:(id)[UIColor greenColor].CGColor range:NSMakeRange(0, [string length])];
double possible de [comment utiliser l'étiquette de coin arrondi iphone, UILabel Coins arrondis] (https://stackoverflow.com/questions/8530115/how-to-use-rounded-corner-label -in-iphone-uilabel-round-coins) –
@NicolasMiari Les coins du texte spécifique, pas UILabel –
Je vois, des mots individuels à l'intérieur d'une seule vue de texte ... Mon mauvais. –