nsattributedstring

Looping Through NSAttributedString Attributes to Increase Font SIze

感情迁移 提交于 2019-11-27 04:03:22
All I need is to loop through all attributes of NSAttributedString and increase their font size. So far I got to the point where I successfully loop through and manipulate attributes but I cannot save back to NSAttributedString . The line I commented out is not working for me. How to save back? NSAttributedString *attrString = self.richTextEditor.attributedText; [attrString enumerateAttributesInRange: NSMakeRange(0, attrString.string.length) options:NSAttributedStringEnumerationReverse usingBlock: ^(NSDictionary *attributes, NSRange range, BOOL *stop) { NSMutableDictionary *mutableAttributes =

How do i convert NSAttributedString into HTML string?

感情迁移 提交于 2019-11-27 03:57:55
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, NSDocumentTypeDocumentAttribute, exclude, NSExcludedElementsDocumentAttribute, nil ]; NSError * error; NSData * htmlData = [self

Cannot convert value of type '[String : AnyObject]?' to expected argument type '[NSAttributedStringKey : Any]?'

拜拜、爱过 提交于 2019-11-27 03:48:38
问题 How to convert values of type '[String : AnyObject]?' to expected argument type '[NSAttributedStringKey : Any]?' ? open class func drawText(context: CGContext, text: String, point: CGPoint, align: NSTextAlignment, attributes: [String : AnyObject]?) { var point = point if align == .center { point.x -= text.size(withAttributes: attributes).width / 2.0 } else if align == .right { point.x -= text.size(withAttributes: attributes).width } NSUIGraphicsPushContext(context) (text as NSString).draw(at:

How to use store and use an NSMutableAttributedString in NSUserDefaults

こ雲淡風輕ζ 提交于 2019-11-27 03:42:33
问题 I want to create an attributed string, then store it in NSUserDefaults , and then access it again and assign the attributed string to textView.attributedText . How do I go about this? Thanks in advance. I don't know a lot of objective c, so I could not refer to this answer 回答1: You have to convert your NSMutableAttributedString into NSData then you store it in NSUserDefaults . // Convert into NSData let data = NSKeyedArchiver.archivedDataWithRootObject(distanceMutableAttributedString)

Wrapping Text in a UITextView Around a UIImage WITHOUT CoreText

会有一股神秘感。 提交于 2019-11-27 03:24:04
Is there a way to wrap text from a UITextView around a UIImage without using CoreText ? I have been playing around with attributed strings without much luck, and CoreText just seems extremely complicated so I would rather stay out of it. Dannie P This seems to do the trick: UIBezierPath * imgRect = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 100, 100)]; self.textView.textContainer.exclusionPaths = @[imgRect]; Works only from iOS 7 and up. The short answer is you can't without CoreText pre iOS 7. I've been struggling with this my self a while ago and the was very helpfull to me. http:/

Change string color with NSAttributedString?

我与影子孤独终老i 提交于 2019-11-27 03:14:16
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 range integer one. self.scanLabel.text=[texts objectAtIndex:sliderValue]; } I want "Very Bad" to be red, "Bad" to be

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

你。 提交于 2019-11-27 03:01:57
问题 Just updated pods for xcode 9 and I'm getting the error below for Cosmos. Type 'NSAttributedStringKey' (aka 'NSString') has no member 'font' 回答1: 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

Swift: Display HTML data in a label or textView

好久不见. 提交于 2019-11-27 03:00:53
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 ? Roger Carvalho 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) } catch { return NSAttributedString() } } var htmlToString: String { return

Convert attributed string, to, “simple” tagged html

落花浮王杯 提交于 2019-11-27 02:22:12
I want to convert an NSAttributedString, to html like this: This is a <i>string</i> with some <b>simple</b> <i><b>html</b></i> tags in it. Unfortunately if you use apple's built-in system it generates verbose css-based html. (Example below for reference.) So how to generate simple tagged html from an NSAttributedString? I wrote a very verbose, fragile call to do it, which is a poor solution. func simpleTagStyle(fromNSAttributedString att: NSAttributedString)->String { // verbose, fragile solution // essentially, iterate all the attribute ranges in the attString // make a note of what style

NSAttributedString superscript styling

痴心易碎 提交于 2019-11-27 01:07:42
I want to superscript all the instances of ® character in a block of text (legal disclaimer, naturally ;)) and the default way NSAttributedString is not very good. If I just let the character be and only use unmodified NSString , it is rendered the same size as a capital letter and is placed approximately at the baseline. If I add the superscript attribute to NSAttributedString as follows: [attrStr setAttributes:@{(NSString *)kCTSuperscriptAttributeName : @1} range:NSMakeRange(locationOfReg, 1)]; The character is lifted off the baseline, its size is unchanged, but the line spacing is now