gpt4 book ai didi

ios - 在现有的 NSMutableAttributed 字符串中添加属性

转载 作者:行者123 更新时间:2023-11-28 18:15:23 30 4
gpt4 key购买 nike

我正在处理一些属性字符串格式。我需要将删除线添加到现有的 NSMutableAttributed 字符串中。在下面给出的示例中是否可能。

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";
}

最佳答案

attributedString 是现有的 NSMutableAttributedString

Objective-C

NSAttributedString 转换为 NSMutableAttributedString

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

添加删除线属性

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

x = 起始索引,y = 字符串长度。

swift :

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

NSAttributedString 转换为 NSMutableAttributedString

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

关于ios - 在现有的 NSMutableAttributed 字符串中添加属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44879905/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com