nsattributedstring

NSAttributedString to NSData No visible @interface for 'NSAttributedString' declares the selector 'RTFDFromRange:documentAttributes:

百般思念 提交于 2019-12-04 05:29:17
I am trying to convert NSAttributedString to NSData using RTFDFromRange method. Getting this: No visible @interface for 'NSAttributedString' declares the selector 'RTFDFromRange:documentAttributes: What is wrong with my code? NSAttributedString *val=self.textview.attributedText; NSData *data = [val RTFDFromRange:NSMakeRange(0, self.textview.text.length) documentAttributes:nil]; NSAttributedString does not have a method called RTFDFromRange for iOS, but only for Mac OS X. To convert NSAttributedString to NSData in iOS, you can try these two approaches: 1. Using initWithData :

NSAttributedString change color at end of string

不羁的心 提交于 2019-12-04 04:00:36
This must be an easy thing to do, but I cannot figure it out. I have a NSMutableAttributedString that has, for example, "This is a test" in it. I want to color the word "test" blue, which I do with this: NSMutableAttributedString *coloredText = [[NSMutableAttributedString alloc] initWithString:@"This is a test"]; [coloredText addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(10,4)]; That works just fine. But now I want to set the text color back to black for anything typed after "test". If I do: [coloredText addAttribute:NSForegroundColorAttributeName

Objective C - Change all attributes in NSAttributedString?

雨燕双飞 提交于 2019-12-04 02:49:11
[attributedString enumerateAttributesInRange:range options:NSAttributedStringEnumerationReverse usingBlock: ^(NSDictionary *attributes, NSRange range, BOOL *stop) { NSMutableDictionary *mutableAttributes = [NSMutableDictionary dictionaryWithDictionary:attributes]; [mutableAttributes setObject:[NSNumber numberWithInt:1] forKey:@"NSUnderline"]; attributes = mutableAttributes; }]; I am trying to loop through all attributed and add NSUnderline to them. when debugging it seems like NSUnderline is added to the dictionary, but when i loop for the second time they are removed. Am I doing anything

How do I display a NSAttributedString on an iPhone? [duplicate]

99封情书 提交于 2019-12-04 01:48:52
This question already has answers here : Closed 6 years ago . iphone/ipad: How exactly use NSAttributedString? (9 answers) I believe I understand how to set NSAttributedString values but how on earth do you actually display them in the interface? examples: UILabel, UITextView, etc. Specific instructions would be greatly appreciated/ Thanks! you could also create a CATextLayer, which works fine with attributed strings... Just create the layer, and set it's string property... Have fun... :D If you don't want to bother with CATextLayer, you should check out TTTAttributedLabel . It's just like

How to draw a border around a paragraph in UILabel?

强颜欢笑 提交于 2019-12-04 01:36:35
问题 I am attempting to use a UILabel that can show rich content. For this I use the attributedText property in UILabel and a NSAttributedString I alloc with NSHTMLTextDocumentType . One type of formatting I want to achieve is to draw a border around paragraphs (for quotes). Normal text formatting like font, bold, italic etc seems to work fine, but when I use CSS properties like border it does not work as I would expect. See picture; only the background-color property is shown. The attributedText

Add NSUnderlineStyle.PatternDash to NSAttributedString in Swift?

大憨熊 提交于 2019-12-03 22:35:15
I'm trying to add an underline to some text in my Swift app. This is the code I have currently: let text = NSMutableAttributedString(string: self.currentHome.name) let attrs = [NSUnderlineStyleAttributeName:NSUnderlineStyle.PatternDash] text.addAttributes(attrs, range: NSMakeRange(0, text.length)) homeLabel.attributedText = text But I get this error on the text.addAttributes line: NSString is not identical to NSObject How can I add an attribute contained in an enum to an NSMutableAttributedString in Swift? Here's a full example of creating a UILabel with underlined text: Swift 5: let homeLabel

UItextView background colours Linespacing area too

纵饮孤独 提交于 2019-12-03 21:42:00
I am trying to replicate the text highlight (Not Search Text Highlight) in my UIText View. But I am Stuck with the colouring in the linespacing as well. How Can I rectify this ? Current situation: Desired Outcome: I have added the following attributes to my UiTextview's Attributed Text For Paragraph Line Spacing I have used the following let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.lineSpacing = 10 For Other Attributes I have used the following verseAttributes : [NSAttributedStringKey : Any] = [ NSAttributedStringKey(rawValue : NSAttributedStringKey.font.rawValue) : UIFont

Rainbow text in TextView, iOS and OSX

匆匆过客 提交于 2019-12-03 21:08:34
I'm trying to add some different text colors to my app to be fused to an image. I've got alot of input that my users would like a rainbow text color and repeat. So for instance the word: stackoverflow would look like this: s=red t=orange a=yellow c=green k=blue o=purple v=pink e=red r=orange f=yellow l=green o=blue w=purple I can't even begin to think how I can do this in one single UITextView Does anyone know how I could achieve this as the user is typing? Tips? Example? I didn't see any other posts on SO regarding rainbow text for iOS. (correct me if im wrong) You can do using

Find CGPoint Location of substring in TextView

杀马特。学长 韩版系。学妹 提交于 2019-12-03 20:59:51
问题 I'm looking to create a SpriteKit Node positioned at the location of a substring inside a UITextView. How would I retrieve the CGPoint location so I can position the SKNode there? let textFont = [NSFontAttributeName: UIFont(name: "GillSansMT", size: 30.0) ?? UIFont.systemFontOfSize(18.0)] attrString1 = NSMutableAttributedString(string: "My name is Dug.", attributes: textFont) textShown1 = CustomTextView(frame: CGRectMake(CGRectGetMidX(self.frame), 175 + (90 * paragraphNumber), CGRectGetWidth

How to detect if a NSAttributedString contains a NSTextAttachment and remove it?

五迷三道 提交于 2019-12-03 17:14:48
I receive as an input a NSAttributedString that may contain an image attached as NSTextAttachment . I need to check if actually such image is attached and, in such case, remove it. I've been looking for related posts with no success, how could I do this? EDIT: I'm trying this: let mutableAttrStr = NSMutableAttributedString(attributedString: textView.attributedText) textView.attributedText.enumerateAttribute(NSAttachmentAttributeName, in: NSMakeRange(0, textView.attributedText.length), options: NSAttributedString.EnumerationOptions(rawValue: 0)) { (value, range, stop) in if (value as?