nsattributedstring

Apply Custom font to Attributed string Which Converts from HTML String

☆樱花仙子☆ 提交于 2019-11-27 14:25:23
I used UITextView in which i display NSAttributedString . i got HTML string from server . I converted HTML to NSAttributedString using below code. NSMutableAttributedString *attrib = [[NSMutableAttributedString alloc]initWithData:[strHTML dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)} documentAttributes:nil error:nil]; To Apply font i tried below 2 codes. apply Attribute Custom String To Apply Attribute i use below code. [attrib addAttribute:NSFontAttributeName value

How to add CSS for HTML to NSAttributedString?

自作多情 提交于 2019-11-27 14:05:30
I am trying to load an HTML file via NSAttributedString to display it in a UITextView . So, how can I apply CSS to the text view's content? André Rodrigues Since iOS 7 you can use NSAttributedString with HTML syntax: NSURL *htmlString = [[NSBundle mainBundle] URLForResource: @"string" withExtension:@"html"]; NSAttributedString *stringWithHTMLAttributes = [[NSAttributedString alloc] initWithFileURL:htmlString options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType} documentAttributes:nil error:nil]; textView.attributedText = stringWithHTMLAttributes; // attributedText field! You have

iOS 7 BUG - NSAttributedString does not appear

百般思念 提交于 2019-11-27 13:55:42
Last week I asked a question about a Simulator bug with NSAttributedString not displaying: iOS 7 Simulator Bug - NSAttributedString does not appear Unfortunately it now appears this is not a simulator bug but an iOS 7 bug. I have now reproduced this issue on an iPhone 5 device. The bug appears to be the combination of using NSUnderlineStyleAttributeName & NSParagraphStyleAttributeName as attributes for a NSAttributedString. I have only tested on two iOS 7 devices so far, and the issue has only appeared on one of them. Even after they have both been upgraded to the exact same version: 1st

NSAttributedString initWithData and NSHTMLTextDocumentType crash if not on main thread

∥☆過路亽.° 提交于 2019-11-27 13:14:36
问题 calling NSAttributedString * as = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)} documentAttributes:nil error:nil]; on other than main thread, results in a crash 1 0x194b861fc <redacted> 2 0x19801d31c <redacted> 3 0x198010eb4 _os_once 4 0x19801aa2c pthread_once 5 0x195a0858c <redacted> 6 0x195a07c78 WebKitInitialize 7

What is the equivalent of Android's “Spannable” in Objective-C

北战南征 提交于 2019-11-27 12:32:40
问题 Im on an iOS app that should able to highlight text, and make it clickable too. I read about NSAttributedString in iOS but it still more complicated than Spannable in android. Is there any other Objective c way to do that, if not; what should i do using NSAttributedString to highlight a paragraph word by word, and how to make my text clickable. Update: What exactly i want that each word should be clickable and can be highlighted as a single word in one paragraph. 回答1: I found a perfect

Saving custom attributes in NSAttributedString

心不动则不痛 提交于 2019-11-27 12:30:59
I need to add a custom attribute to the selected text in an NSTextView. So I can do that by getting the attributed string for the selection, adding a custom attribute to it, and then replacing the selection with my new attributed string. So now I get the text view's attributed string as NSData and write it to a file. Later when I open that file and restore it to the text view my custom attributes are gone! After working out the entire scheme for my custom attribute I find that custom attributes are not saved for you. Look at the IMPORTANT note here: http://developer.apple.com/mac/library

Storing NSAttributedString Core Data

删除回忆录丶 提交于 2019-11-27 10:54:23
问题 I am trying to store an NSAttributedString to a Core Data SQL store. I have the property set as a "transformable", it is optional and it is NOT transient or indexed and the value transformer name is set to default "NSKeyedUnarchiveFromData". In the .xcdatamodel and generated the managed object class which has this in the .h: @property (nonatomic, retain) id Text; (I have tried changing id to NSAttributedString *Text) and this in the .m: @dynamic Text; I look through and set the ".text"

iOS NSAttributedString to HTML

本秂侑毒 提交于 2019-11-27 10:52:51
问题 I have an NSAttributed string (coming from HTML) that I set for a UITextView . - (void)setHtml:(NSString *)html { NSData *htmlData = [html dataUsingEncoding:NSUTF8StringEncoding]; // Create the HTML string NSDictionary *importParams = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType}; NSError *error = nil; self.htmlString = [[NSAttributedString alloc] initWithData:htmlData options:importParams documentAttributes:NULL error:&error]; self.editorView.attributedText = self.htmlString; }

UITextView: Disable selection, allow links

不羁的心 提交于 2019-11-27 10:47:50
问题 I have a UITextView which displays an NSAttributedString . The textView's editable and selectable properties are both set to false . The attributedString contains a URL and I'd like to allow tapping the URL to open a browser. But interaction with the URL is only possible if the selectable attribute is set to true . How can I allow user interaction only for tapping links, but not for selecting text? 回答1: I find the concept of fiddling with the internal gesture recognizers a little scary, so

How to get height for NSAttributedString at a fixed width

无人久伴 提交于 2019-11-27 09:50:26
问题 I want to do some drawing of NSAttributedStrings in fixed-width boxes, but am having trouble calculating the right height they'll take up when drawn. So far, I've tried: Calling - (NSSize) size , but the results are useless (for this purpose), as they'll give whatever width the string desires. Calling - (void)drawWithRect:(NSRect)rect options:(NSStringDrawingOptions)options with a rect shaped to the width I want and NSStringDrawingUsesLineFragmentOrigin in the options, exactly as I'm using in