textkit

Using a CALayer to highlight text in a UITextView which spans multiple lines

隐身守侯 提交于 2019-11-28 20:38:09
问题 This is a continuation of Getting CGRect for text in a UITextView for the purpose of highlighting with a CALayer. I'm having trouble with getting the correct rectangle for the ranges in each line fragment. NSString* searchString = @"Returns the range of characters that generated"; NSRange match = [[[self textView]text]rangeOfString:searchString]; NSRange matchingGlyphRange = [manager glyphRangeForCharacterRange:match actualCharacterRange:NULL]; [manager enumerateLineFragmentsForGlyphRange

iOS NSAttributedString to HTML

為{幸葍}努か 提交于 2019-11-28 17:54:32
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; } I then let the user edit what they want, and I would like to then convert it out to HTML again, so I

UITextView – can't set underline or strikethrough attributes on text?

隐身守侯 提交于 2019-11-28 13:21:08
I'm getting runtime failures whenever I try to set underline or strikethrough attributes on the attributedText of a UITextView. Other properties, like font and background color have no problems. Here's a code snippet. All I have is a test project with a single UITextView. I'm on iOS 11. class ViewController: UIViewController { @IBOutlet weak var myTextView: UITextView! var myMutableString = NSMutableAttributedString(string: "") override func viewDidLoad() { super.viewDidLoad() let string = "The cow jumped over the moon" as NSString myMutableString = NSMutableAttributedString(string: string as

Newlines in iOS 7 UITextView breaking Text Kit exclusion zone wrapping

烈酒焚心 提交于 2019-11-27 17:03:01
问题 I'm working with Text Kit in iOS 7 and I'm finding a lot of oddities around NSTextContainer exclusion zones. I've got two views: a UITextView and a simple draggable UIView ; as the UIView moves, I create a bezier path from the UIView 's frame (adjusted to within the UITextView 's coordinate space) and I update the UITextView 's NSTextContainer 's exclusionPaths array - pretty straightforward. In the first screenshot, you can see that Text Kit nicely wraps text around a rectangular exclusion

Get line information from UITextView and NSLayoutManager

时间秒杀一切 提交于 2019-11-27 13:56:32
问题 In order to support the UIAccessibilityReadingContent protocol, I need my UITextView to answer me questions about its lines. These are the methods of the protocol that I need to implement: accessibilityLineNumberForPoint: <- Provided a coordinate, return a line number accessibilityContentForLineNumber: <- Return the text of a given line accessibilityFrameForLineNumber: <- Given a line number, return its frame accessibilityPageContent <- The entire text content. That I have. :) I figure that

Character index at touch point for UILabel

自闭症网瘾萝莉.ら 提交于 2019-11-27 12:44:22
For a UILabel , I'd like to find out which character index is at specific point received from a touch event. I'd like to solve this problem for iOS 7 using Text Kit. Since UILabel doesn't provide access to its NSLayoutManager , I created my own based on UILabel 's configuration like this: - (void)textTapped:(UITapGestureRecognizer *)recognizer { if (recognizer.state == UIGestureRecognizerStateEnded) { CGPoint location = [recognizer locationInView:self]; NSTextStorage *textStorage = [[NSTextStorage alloc] initWithAttributedString:self.attributedText]; NSLayoutManager *layoutManager = [

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 – can't set underline or strikethrough attributes on text?

元气小坏坏 提交于 2019-11-27 07:37:39
问题 I'm getting runtime failures whenever I try to set underline or strikethrough attributes on the attributedText of a UITextView. Other properties, like font and background color have no problems. Here's a code snippet. All I have is a test project with a single UITextView. I'm on iOS 11. class ViewController: UIViewController { @IBOutlet weak var myTextView: UITextView! var myMutableString = NSMutableAttributedString(string: "") override func viewDidLoad() { super.viewDidLoad() let string =

Character index at touch point for UILabel

痴心易碎 提交于 2019-11-26 19:59:11
问题 For a UILabel , I'd like to find out which character index is at specific point received from a touch event. I'd like to solve this problem for iOS 7 using Text Kit. Since UILabel doesn't provide access to its NSLayoutManager , I created my own based on UILabel 's configuration like this: - (void)textTapped:(UITapGestureRecognizer *)recognizer { if (recognizer.state == UIGestureRecognizerStateEnded) { CGPoint location = [recognizer locationInView:self]; NSTextStorage *textStorage = [

How to embed small icon in UILabel

半城伤御伤魂 提交于 2019-11-26 14:53:28
I need to embed small icons ( sort of custom bullets ) to my UILabel in iOS7. How can I do this in interface designer? Or at least in code? In Android there are leftDrawable and rightDrawable for labels, but how it is done in iOS? Sample in android : Scott Berrevoets You can do this with iOS 7's text attachments , which are part of TextKit. Some sample code: NSTextAttachment *attachment = [[NSTextAttachment alloc] init]; attachment.image = [UIImage imageNamed:@"MyIcon.png"]; NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];