jjzjj

effectiveRange

全部标签

ios - [NSConcreteTextStorage 属性 :atIndex:effectiveRange:]: Range or index out of bounds error in NSMutableAttributedString

我正在尝试创建一个属性字符串,其中在字符串末尾附加了一个链接:funcaddMoreAndLessFunctionality(textView:UITextView){iftextView.text.characters.count>=120{letlengthOfString=255varabc:String=(somelongStringInitiallyAvailableasNSString).substringWithRange(NSRange(location:0,length:lengthOfString))abc+="...More"textView.text=abcle

ios - 将 NSRangePointer 从 Objective-C 翻译成 Swift

我在将一些Objective-C代码转换为Swift时遇到错误。我正在使用- attribute:atIndex:effectiveRange:NSAttributedString并且有关于effectiveRange参数的错误,它是一个NSRangePointer。objective-C:NSRangerange;idvalue=[self.textanalyzeattribute:attributeatIndex:indexeffectiveRange:&range]swift:varrange:NSRange?varvalue:Any=self.textanalyze.attri

ios - 将 NSRangePointer 从 Objective-C 翻译成 Swift

我在将一些Objective-C代码转换为Swift时遇到错误。我正在使用- attribute:atIndex:effectiveRange:NSAttributedString并且有关于effectiveRange参数的错误,它是一个NSRangePointer。objective-C:NSRangerange;idvalue=[self.textanalyzeattribute:attributeatIndex:indexeffectiveRange:&range]swift:varrange:NSRange?varvalue:Any=self.textanalyze.attri

ios - 错误 "NSMutableRLEArray objectAtIndex:effectiveRange::Out of bounds'“

我有以下代码,其中我传递了一个"Hello|rWorld|g"类型的字符串,下面的函数将它转换为attributedString"Hello"为红色,"World"为绿色。我在传递数组中的每个字符串时使用了它。该函数只为文本着色,直到它找到最后期间条件中显示的特殊字符,然后为文本着色。代码:funcformatAttributedString(string:String)->NSMutableAttributedString{varstrCopy=stringasNSStringvarcolor:UIColor=UIColor()varattributedString:NSMutabl