textkit

Hide Markdown Characters with NSLayoutManager in Swift

橙三吉。 提交于 2020-08-01 09:05:10
问题 I am working on a rich text editor in a Mac app that uses Markdown syntax. I use NSTextStorage to watch for matches in Markdown syntax, then apply styles to the NSAttributedString in real time like this: At this point, I'm already in way over my head on this stuff, but I'm excited to be making progress. :) This tutorial was very helpful. As a next step, I want to hide the Markdown characters when the NSTextView 's string is rendered. So in the example above, once the last asterisk is typed, I

Control spacing around custom text attributes in NSLayoutManager

痴心易碎 提交于 2020-06-09 12:50:47
问题 I’ve got a custom NSLayoutManager subclass I’m using to draw pill-shaped tokens. I draw these tokens for substrings with a custom attribute ( TokenAttribute ). I can draw no problem. However, I need to add a little bit of “padding” around the ranges with my TokenAttribute (so that the round rectangle background of the token won’t intersect with the text). In the above image, I’m drawing my token’s background with an orange colour, but I want extra padding around 469 so the background isn’t

what to use instead of scrollRangeToVisible in iOS7 or TextKit

橙三吉。 提交于 2020-01-11 04:49:14
问题 In previous versions of iOS, my UITextView will scroll to the bottom using [displayText scrollRangeToVisible:NSMakeRange(0,[displayText.text length])]; or CGFloat topCorrect = displayText.contentSize.height -[displayText bounds].size.height; topCorrect = (topCorrect<0.0?0.0:topCorrect); displayText.contentOffset = (CGPoint){.x=0, .y=topCorrect}; But the former will now have the weird effect of starting at the top of a long length of text and animating the scroll to the bottom each time I

How to make UITableView row height respond to user's preferred text size (Dynamic Type)?

冷暖自知 提交于 2020-01-01 19:42:10
问题 I would like the UITableView 's row height to respond to changes in the user's preferred text size. For example, when the preferred text size increases, I would like to increase the row height by a proportional amount. Here's what I have so far: - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.tableView reloadData]; // observe when user changes preferred text size [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector

Make selected string of text view Bold, Italic, Underline like native “Notes” app of iOS

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-30 11:33:08
问题 Is there any help to make selected string of text view Bold, Italic, Underline like native "Notes" app of iOS. Please give me helpful links. I am tired of searching for the whole day. Many Thanks. I have attached my code, to make attributed string Bold and Italic both like native app of iPhone "Notes". attributedString.beginEditing() attributedString.addAttributes([NSFontAttributeName: UIFont.boldSystemFont(ofSize: CGFloat(app_delegate.settings.chatFontSize))], range: range) attributedString

Lines missing from tall UILabel when embedding NSTextAttachment

佐手、 提交于 2019-12-29 05:47:09
问题 I can create a multi-line NSAttributedString by using escaped new-line characters ( @"\n" ). With iOS 7, I can now embed a UIImage inside attributed strings (via NSTextAttachment ). I have noticed that whenever I set the attributedText of a UILabel to a multi-line attributed string with an embedded image, the number of lines actually displayed is inversely proportional to the height of the label. For example, when the height of the label is 80, two lines appear; when the height is around 100,

iOS7 Type into UITextView with Line Spacing and keep formatting using TextKit

十年热恋 提交于 2019-12-25 03:18:29
问题 I came across this great example which helped me understand how I can achieve line spacing / paragraph spacing as you type inside a UITextView with iOS7, however there is a problem and I am hoping someone can help me with resolving an issue as I am still learning about TextKit please. This is the actual example https://github.com/downie/DoubleSpacedTextView I have attached 2 files:- 1- This is a video of the problem:- http://1drv.ms/1o8Rpd2 2- This is the project I am testing with: http:/

NSTextView's Insertion Point draws position exceptions

跟風遠走 提交于 2019-12-24 18:56:48
问题 This should be a Bug, because I can reproduce it with my friends. I just set allowsNonContiguous Layout of NSTextView. layoutManager to true, and that's the problem. In the editor, I first enter N blank lines, that is, press N times to return. Then go back to the second line of our input, and press any key at the moment insertion Point disappears, which will make my insertion Point incorrect. Here is my demo: https://github.com/iiiDD/TextViewDemo 回答1: I had the same problem. I’ve detailed how

When creating a series of NSTextContainers, how do I specify container breaks based on the text content?

◇◆丶佛笑我妖孽 提交于 2019-12-22 09:22:36
问题 I'm creating a series of NSTextContainers to hold the text from an HTML resource. I am able to add the HTML to an attributed string, assign that to a NSTextStorage and NSLayoutManager, and create a series of NSTextContainers to hold all the text. My problem is, I want to add "page breaks" within the text, i.e. stop filling this text container and start another... In the documentation, I've found something call NSControlCharacterContainerBreakAction; but I'm unclear how to implement it or if

UITextView - Highlight text with NSBackgroundColor - exclude line breaks

余生颓废 提交于 2019-12-21 05:22:20
问题 I have a working feature with text highlighting, the problem is that it also highlights line break. See the image: Below is a function I use for highlighting: -(void)setHighlight{ //set highlighted __block BOOL textIsHighlited = YES; [self.attributedText enumerateAttributesInRange:[self selectedRange] options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired usingBlock:^(NSDictionary *attrs, NSRange range, BOOL *stop) { if ([attrs valueForKey:@"NSBackgroundColor"] == Nil) {