nsattributedstring

HTML to NSAttributedString and NSAttributedString to HTML

独自空忆成欢 提交于 2019-11-26 16:55:19
问题 i have a problem with NSAttributedString ... I want to convert a HTML string into an NSAttributedString and then work on the NSAttributedString (change some colors, fontsize, fontfamily, background- , foreground-Color) and then convert back plain HTML text from the NSAttributedString. Converting isn't a problem , but on each time I convert HTML to NSAS and back the fontsize getting bigger and bigger ?! Here is a picture and source code of my playground. // Playground - noun: a place where

Extract UIImage from NSAttributed String

我与影子孤独终老i 提交于 2019-11-26 16:44:09
What I am doing is: NSATTRIBUTE STRING = NSSTRING + UIIMAGE's; NSDATA = NSATTRIBUTED STRING; ALSO I am able to convert nsdata to nsattributed string NSATTRIBUTED STRING = NSDATA: And then extracting nesting from NSAttributed string NSSTRING = [NSATTRIBUTED STRING string]; Query: How can i get IMAGES from NSATTRIBUTED STRING; UIIMAGE = from NSATTRIBUTED STRING; ARRAYOFIMAGE = from NSATTRIBUTED STRING; You have to enumerate the NSAttributedString looking for NSTextAttachment s. NSMutableArray *imagesArray = [[NSMutableArray alloc] init]; [attributedString enumerateAttribute

How to add CSS for HTML to NSAttributedString?

自作多情 提交于 2019-11-26 16:35:53
问题 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? 回答1: 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

Find attributes from attributed string that user typed

落花浮王杯 提交于 2019-11-26 14:20:09
问题 In my app the User will type anything that he wants and he can make the text Bold, Italic and Underline. I am able to do the Text - Bold, Italic and Underline. But I need to find which Text (or Character) is Bold, Italic and Underline from the attribute string that user typed . Any types of link, tutorial, code will be great help. EDIT : I need the result like this... if character 6 is Italic then print Italic. if character 14 is Bold then print Bold. I need to convert all the text from

How can I both stroke and fill with NSAttributedString w/ UILabel

巧了我就是萌 提交于 2019-11-26 13:45:19
问题 Is it possible to apply both stroke and fill with an NSAttributedString and a UILabel ? 回答1: Yes, the key is to apply a Negative value to the NSStrokeWidthAttributeName If this value is positive you will only see the stroke and not the fill. Objective-C: self.label.attributedText=[[NSAttributedString alloc] initWithString:@"string to both stroke and fill" attributes:@{ NSStrokeWidthAttributeName: @-3.0, NSStrokeColorAttributeName:[UIColor yellowColor], NSForegroundColorAttributeName:[UIColor

Copy NSAttributedString in UIPasteBoard

一笑奈何 提交于 2019-11-26 11:18:38
问题 How do you copy an NSAttributedString in the pasteboard , to allow the user to paste, or to paste programmatically (with - (void)paste:(id)sender , from UIResponderStandardEditActions protocol). I tried: UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard]; [pasteBoard setValue:attributedString forPasteboardType:(NSString *)kUTTypeRTF]; but this crash with: -[UIPasteboard setValue:forPasteboardType:]: value is not a valid property list type\' which is to be expected, because

How do i convert NSAttributedString into HTML string?

余生长醉 提交于 2019-11-26 10:58:18
问题 As the title tells,now i can simple convert HTML into NSAttributedString with initWithHTML:documentAttributes: , but what i want to do here is reverse. Is there any 3rd party library to achieve this? @implementation NSAttributedString(HTML) -(NSString *)htmlForAttributedString{ NSArray * exclude = [NSArray arrayWithObjects:@\"doctype\", @\"html\", @\"head\", @\"body\", @\"xml\", nil ]; NSDictionary * htmlAtt = [NSDictionary dictionaryWithObjectsAndKeys:NSHTMLTextDocumentType,

Change string color with NSAttributedString?

我只是一个虾纸丫 提交于 2019-11-26 10:23:54
问题 I have a slider for a survey that display the following strings based on the value of the slider: \"Very Bad, Bad, Okay, Good, Very Good\". Here is the code for the slider: - (IBAction) sliderValueChanged:(UISlider *)sender { scanLabel.text = [NSString stringWithFormat:@\" %.f\", [sender value]]; NSArray *texts=[NSArray arrayWithObjects:@\"Very Bad\", @\"Bad\", @\"Okay\", @\"Good\", @\"Very Good\", @\"Very Good\", nil]; NSInteger sliderValue=[sender value]; //make the slider value in given

Swift: Display HTML data in a label or textView

大城市里の小女人 提交于 2019-11-26 10:20:23
问题 I have some HTML data, which contains headings, paragraphs , images and lists tags. Is there a way to display this data in one UITextView or UILabel ? 回答1: For Swift 4: extension String { var htmlToAttributedString: NSAttributedString? { guard let data = data(using: .utf8) else { return NSAttributedString() } do { return try NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding:String.Encoding.utf8.rawValue], documentAttributes: nil)

ios7 font size change when create nsattributedstring from html

不问归期 提交于 2019-11-26 09:43:27
问题 I have a UITextView where I\'m managing an NSAttributedString, initially entered as normal via the keyboard. I save the attributed string as HTML, which looks fine. When I load it again, and convert it back to an attributed string from the HTML, the font size appears to change. For example, the HTML on loading looks like this: <!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"> <html> <head> <meta http-equiv=\"Content-Type\" content=\"text/html;