nsattributedstring

Convert NSAttributedString into Data for storage

元气小坏坏 提交于 2019-11-29 11:09:51
I have a UITextView with attributed text and allowsEditingTextAttributes set to true . I'm trying to convert the attributed string into a Data object, using the following code: let text = self.textView.attributedText let data = try text.data(from: NSMakeRange(0, text.length), documentAttributes: [:]) However, this is throwing the following error: Error Domain=NSCocoaErrorDomain Code=66062 "(null)" Any ideas what this error means or what could cause this? I'm on the latest Xcode and iOS. Thanks. You need to specify what kind of document data you would like to convert your attributed string to:

NSAttributedString from HTML in the background thread

十年热恋 提交于 2019-11-29 11:08:34
What I need is to create NSAttributedString objects from relatively big HTML strings and store them (NSAttributedString-s) in the database. And of course I would like to do that in the background thread. Here is a simple code (which fails) to demonstrate what I'm trying to do: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSString *HTMLString = @"<p>HTML string</p>"; NSDictionary *options = @{NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute : @(NSUTF8StringEncoding)}; NSError *error = nil; NSAttributedString

How do I add tab stops to an NSAttributedString and display in a UITextView

送分小仙女□ 提交于 2019-11-29 10:28:15
问题 I'm creating an iOS app, and I would like to display an attributed string with specific tab stops specified in a UITextView. I would also like to draw them directly into UIViews using Core Text in drawRect. I would like (if possible) for the same attributed string to be used in both scenarios. So, in my app, I create an CFAttributedStringRef or an NSAttributedString and apply a CTParagraphStyle attribute to it. Then, I attempt to display the attributed string in a UITextView and I get a crash

How to paste rich text into a UITextView?

帅比萌擦擦* 提交于 2019-11-29 08:24:44
My app allows users to format text in a UITextView by clicking some formatting buttons that apply attributes to the attributedText property of the text view. I want to allow users to copy their formatted text from one UITextView and paste it into another using the standard pasteboard and standard cut/copy/paste menu. Currently if I copy formatted text from a UITextView and paste it into a new message in the Mail app, the formatting is preserved -- so the copying of formatted text is happening automatically. But if I paste the formatted text into another UITextView in my app, only the plain

Markdown to NSAttributedString library? [closed]

♀尐吖头ヾ 提交于 2019-11-29 06:14:29
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Now that NSAttributedString is fully supported in iOS 6, is there a library that will take an NSString with markdown, and convert it to NSAttributedString? 回答1: I've just added an NSString to NSAttributedString lightweight markup parser to MGBoxKit. It's not Markdown but it's very similar. So far it supports

Transform an NSAttributedString to plain text

半世苍凉 提交于 2019-11-29 05:26:24
I have an instance of NSData containing attributed text ( NSAttributedString ) originating from an NSTextView . I want to convert the attributed string to a plain string ( NSString ) without any formatting to do some text analysis (at the moment of conversion I do not have access to the originating NSTextView nor its NSTextStorage instance). What would be the best way to do this? EDIT: Out of curiosity I examined the result of: [[[self textView] textStorage] words] which appeared to be a handy thing for doing some text analysis. The resulting array contains instances of NSSubTextStorage

How could you make a uilabel wrap around an image (like shown)

强颜欢笑 提交于 2019-11-29 04:06:29
How could you achieve this effect: Maybe some sort of NSAtributedString? I have thought of hacky ways to just add spaces, but it needs to do it dynamically based on the width of the image. Any ideas? NOTE happily you can do this very easily with UITextView: https://stackoverflow.com/a/20033752/294884 this question is about UILabel. Add image in your label with text as below code: NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"Here is some text that is wrapping around like an image"]; NSTextAttachment *textAttachment = [[NSTextAttachment alloc]

Type 'NSAttributedStringKey' (aka 'NSString') has no member 'font'

杀马特。学长 韩版系。学妹 提交于 2019-11-29 02:49:17
Just updated pods for xcode 9 and I'm getting the error below for Cosmos . Type 'NSAttributedStringKey' (aka 'NSString') has no member 'font' Note: Ensure swift language version of your project. Here is how you can see/check your swift language version. You have two options as solution to your query: If your project has Swift versio 4.0 - You should choose/download POD compatible to your project's swift language (Share me POD info and swift version, so I can provide you exact pod version version for your pod library suitable for project). If your project has swift version below 4.0 - You need

Advance search implementation in iphone?

微笑、不失礼 提交于 2019-11-29 02:06:55
I want to implement advance search functionality so that if a particular text is typed in search bar, the list of contents in UITableview should be filtered based on the search and then the search text occurances should be highlighted? Please give me some ideas? Use NSAttributedString... Find UIControllers that draw NSAttribute String because UILabel,UITextView doesnot support NSAttributedString... Get the controller here: https://github.com/AliSoftware/Ali-Cocoa-Classes/tree/master/OHAttributedLabel PS: if you plan to distribute an iOS6-only application, as UILabel now support

Are there any analogues of [NSString stringWithFormat:] for NSAttributedString

你。 提交于 2019-11-29 02:01:20
Usually I build app interface in interface builder. Sometimes design requires to use attributed strings (fonts, colors and etc.). It's easy to configure if string is static. But if string is dynamic (format with arguments) then there are no ways to configure attributes in interface builder. It requires to write a lot of code. I am looking for some analogues of [NSString stringWithFormat:] for NSAttributedString . So I will be able to set string format and necessary attributes in interface builder, and then provide necessary arguments in code. For example: Let's consider that I need display