2017-07-03 2 views
-1

Je travaille sur un format de chaîne attribué. Je dois ajouter une suppression dans la chaîne NSMutableAttributed existante. Est-il possible dans l'exemple donné ci-dessous.Ajouter un attribut dans une chaîne NSMutableAttributed existante

First Task For Bhasin 
30 Jun 2017 12:05 PM till 30 Jun 2017 01:05 PM{ 
NSBackgroundColor = "<CGColor 0x6100000934c0> [<CGColorSpace 0x6080000303c0> (kCGColorSpaceICCBased; kCGColorSpaceModelMonochrome; Generic Gray Gamma 2.2 Profile; extended range)] (0 0)"; 
NSColor = "<CGColor 0x6180002a2ac0> [<CGColorSpace 0x610000230920> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1; extended range)] (1 0 0 1)"; 
NSFont = "<UICTFont: 0x7fac5476a0b0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 15.00pt"; 
NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (\n), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0"; 
} 

Toute aide sera appréciée

+0

Ajoutez le code de 'attributedString' – Subramanian

+0

@Subramanian, j'utilise DAAttributedStringFormatter. Je souhaite ajouter une suppression – gurmandeep

+0

Ajoutez la réponse pour convertir 'NSAttributedString' en' NSMutableAttributedString' et en ajoutant l'attribut strike through. – Subramanian

Répondre

1

attributedString est le NSMutableAttributedString existant.

Objectif C

Convertir NSAttributedString à NSMutableAttributedString

NSMutableAttributedString *attributedString = [NSMutableAttributedString alloc]initWithAttributedString:<#Your String Here#>]; 

Ajouter Strikethrough Attribute

[attributedString addAttributes:@{ NSStrikethroughStyleAttributeName : [NSNumber numberWithInteger:NSUnderlineStyleSingle]} range:NSMakeRange(x, y)]; 

x = indice de départ, y = longueur de la chaîne.

Swift:

attributedString.addAttributes([NSStrikethroughStyleAttributeName: NSNumber(integer: NSUnderlineStyle.StyleSingle.rawValue)], range: NSMakeRange(x, y)) 

Convertir NSAttributedString à NSMutableAttributedString

let attributedString:NSMutableAttributedString = NSMutableAttributedString(attributedString: <#NSAttributedString#>) 
+0

Down vote sans commentaire n'aidera pas – Subramanian

+0

Je cherche le code Obj c. – gurmandeep

+0

Déjà ajouté. Et ajoutez votre question à l'objectif c. Cela aidera donc les gens à identifier la langue préférée. – Subramanian