nsattributedstring

NSTextField's attributed string is delayed in rendering

怎甘沉沦 提交于 2019-12-05 06:19:36
I've got an Label (NSTextField) in IB that's bound to a controller. The controller, on awakeFromNIB, sets the attributedStringValue of the label to contain some coloured text and a link or two. When you see the label it contains the correct string value, but some of the formatting is lost - until you click on the label, and it updates to contain the correct formatting. I'm using this code to set the value: [self.testTextField setAllowsEditingTextAttributes:YES]; [self.testTextField setSelectable:YES]; NSMutableAttributedString *linkString = [[NSMutableAttributedString alloc] initWithString:@

Technique on how to format/color NSTextView's string

那年仲夏 提交于 2019-12-05 05:35:20
I'm looking for a reliable technique to do simple string formatting(bold, italic,...) in a NSTextView. The text parsing is almost done with regex, but now I need to apply font trait and also change the size. Some code snippets on how I make a text bold [[textView textStorage] beginEditing]; [[textView textStorage] applyFontTraits:NSFontBoldTrait range:range]; [[textView textStorage] endEditing]; This and also the size changes with [[textView textStorage] beginEditing]; NSFont* font = [[textView textStorage] attribute:NSFontAttributeName atIndex:range.location effectiveRange:nil]; NSFont*

UITextView crash in iOS 8 with attributed string containing a table

纵然是瞬间 提交于 2019-12-05 04:08:47
In iOS 8 (or possibly even in iOS 7/7.1) NSAttributedString on iOS added the ability to render text tables. This API is public on OS X but not on iOS. However, it is possible to create an attributed string containing a text table on iOS by passing HTML containing a table to -[NSAttributedString initWithData:options:documentAttributes:error:] . The attributed string is created correctly, but when I attempt to render the string using a UITextView , this exception gets thrown: <NSATSTypesetter: 0x7f8900faec90>: Exception *** -[NSConcreteTextStorage attribute:atIndex:effectiveRange:]: Range or

Large Navigation Bar Text With Multiple Colors

北慕城南 提交于 2019-12-05 03:39:36
iOS 11 introduces the option for larger text in the Navigation Bar. I would like to have a title that uses multiple colors. For example: It's fairly easy to set the title, and even to change the color of the entire title: [[self navigationItem] setTitle: @"Colors"]; [[[self navigationController] navigationBar] setLargeTitleTextAttributes: @{NSForegroundColorAttributeName: [UIColor colorFromHex: redColor]}]; What I can't figure out is how to change just part of the title. For example, a way to select the range like this – NSRangeMake(0, 1) – so that I could apply a color to it. This must be

Convert attributed text to HTML in Swift 4

丶灬走出姿态 提交于 2019-12-05 03:21:48
I am trying to convert attributed text to HTML in Swift 4 so that it can be stored in Firebase/Firestore and synced across different devices/platforms. I have read every article I can find on Stackoverflow including Convert attributed string, to, "simple" tagged html , Convert attributed text to HTML and this blog article: http://sketchytech.blogspot.com/2016/02/swift-from-html-to-nsattributedtext-and.html . I am finding that Swift 4.x throws an unresolved identifier error for NSDocumentTypeDocumentAttribute and NSHTMLTextDocumentType in the various code examples there are (example below).

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

。_饼干妹妹 提交于 2019-12-05 02:10:24
问题 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

How to adjust a UILabel line spacing programmatically in Swift?

喜夏-厌秋 提交于 2019-12-05 01:44:08
问题 I have a multiline UILabel as shown here: I achieved this using the following code: label.lineBreakMode = .ByWordWrapping label.numberOfLines = 2 I'm trying to "decrease" the line spacing between the 1st line and 2nd line, and I tried to use the following code: let text = label.attributedText let mas = NSMutableAttributedString(attributedString:text!) mas.replaceCharactersInRange(NSMakeRange(0, mas.string.utf16.count), withString: label.text!) label.attributedText = mas However, it does not

Confused by NSStringDrawingOptions item meaning

社会主义新天地 提交于 2019-12-05 01:08:57
iOS7 and later, we can use - (void)drawWithRect:(CGRect)rect options:(NSStringDrawingOptions)options attributes:(NSDictionary *)attributes context:(NSStringDrawingContext *)context to calculate the string size, but I'm confused with the comments on NSStringDrawingOptions enum. NSStringDrawingUsesLineFragmentOrigin It means specified origin is the line fragment origin, not the base line origin. But what mean of line fragment origin and baseline origin. Just like the WWDC 2013 Session 220 (Advanced Text Layouts and Effects with Text Kit) PDF on Page 95. If line fragment origin mean the blue dot,

NSTextAlignmentJustified not working in iOS7

淺唱寂寞╮ 提交于 2019-12-05 00:29:34
I have an app which uses NSTextAlignmentJustified for an NSAttributedString . In iOS 6 everything is working great. But the same App running in iOS 7 (simulator or device makes no difference) is showing no Justify at all. Also the linespacing seems to have changed dramatically from iOS 6 to 7 . Anyone else encountered this problem? Is there any way to make a justified Textblock in iOS 7 (which works in iOS 6 too?) Regards, Markus Ok, i kind of found a way to make the label Justifiy in iOS 7: i simply set NSBaselineOffsetAttributeName to 0. No idea why it works, but it works.

Is Rounded Corners on Attributed Text Background possible?

依然范特西╮ 提交于 2019-12-05 00:21:40
问题 I attributed Text with different textcolors. For better readability on highlighted text i use backgroundcolor. Is it possible to bring the CALayer Effect of Rounded Corners on this Textarea? Not the whole Area but the special Text inside of it. My Code: NSAttributedString *text = [[NSAttributedString alloc] initWithString:@"Highlighted Text" attributes:@{ NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:10.0f], NSForegroundColorAttributeName: [UIColor lightGrayColor],