textkit

iOS 7 UITextView: Size of nstextattachment getting 2x after reopening the application

白昼怎懂夜的黑 提交于 2019-12-05 05:15:43
I am building a note editor using the Text Kit in ios7. Earlier I had trouble in rendering of custom size NSTextAttachment's as it was slowing down the rendering to a great extent.I solved the issue by scaling the images and then adding them to textview.You can find my answer in iOS 7.0 UITextView gettings terribly slow after adding images to it After scaling the images the textview rendering runs fine without any lag.The attributed text of textview is stored in core data.During a running session of application the textview displays the images correctly.Even after saving the attributed text in

UIPageViewController/TextKit Reflowing Text on paging

…衆ロ難τιáo~ 提交于 2019-12-05 01:09:21
问题 I'm working on a multi-page reading application backed by TextKit, based off of the "Advanced Text Layouts and Effects with Text Kit" session from WWDC 2013 (but with some code reconstructed from incomplete example). The basic structure is you calculate the number of pages needed for your text upfront, then create an NSTextContainer for each page and add it to the NSLayoutManager. Whenever the UIPageViewController asks for the next or previous page, you create a new UITextView and set its

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,

Getting CGRect for text in a UITextView for the purpose of highlighting with a CALayer

Deadly 提交于 2019-12-05 01:08:11
问题 I am trying to draw a transparent CALayer in a UITextView in order to highlight matched text in a search. I've figured out the correct way to do this, but still haven't found the correct coordinates. I need to find the origin of the text container. Right now, I get the textView's origin, and offset the layer's origin by that: NSRange match = [[[self textView]text]rangeOfString:@"predict the future"]; NSRange glyphRange = [manager glyphRangeForCharacterRange:match actualCharacterRange:NULL];

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

烈酒焚心 提交于 2019-12-04 19:35:29
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(preferredContentSizeChanged:) name:UIContentSizeCategoryDidChangeNotification object:nil]; } - (void)preferredContentSizeChanged:

Sub-Classing NSTextStorage Causes Significant Memory Issues

廉价感情. 提交于 2019-12-04 13:17:39
问题 I have a custom UITextView that takes advantage of Apple's TextKit by defining a custom NSTextStorage class, however, when I use my subclass for the custom text view's, text storage (as implemented below) and try opening any file greater than 20.0KB, the app crashes due to memory leakage: " Message from debugger: Terminated due to memory issue ". Oddly enough, if I replace my custom BMTextStorage with just a standard one, NSTextStorage , the text loads instantly without any memory leakage and

Example of NSTextContainer with non regular shape?

故事扮演 提交于 2019-12-04 10:57:28
问题 Hi I'm working with the new TextKit API for iOS7 and I'm trying to produce a UITextView with an irregular shape. So far I have in a view controller: -(void) loadView { self.view = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,548)]; NSTextStorage *textStorage = [[NSTextStorage alloc] init]; NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init]; [textStorage addLayoutManager: layoutManager]; BaseTextContainer *textContainer = [[BaseTextContainer alloc] initWithSize:CGSizeMake(100,

Calculate cell height for TextView with exclusion paths

六眼飞鱼酱① 提交于 2019-12-04 04:21:33
If I have a TextView with exclusion paths in a UITableViewCell , how can I calculate the cell's height for a given string? I found a solution which I think might be of help to others. Since it does not require the creation of a new NSTextContainer, NSLayoutManager, and NSTextStorage object, which are already instantiated as part of the UITextView, I suspect it would be more efficient. To calculate the size of a UITextView that is using exclusions paths and NSAttributedString, one can do the following: // Assuming something like this... UIBezierPath * exclusionPath = [UIBezierPath

iOS Drawing text in the centre of shapes

断了今生、忘了曾经 提交于 2019-12-04 01:18:41
问题 I'm trying to draw text in the centre of shapes in iOS, an example would be Microsoft Office's insert shape see: https://www.dropbox.com/s/cgqyyuvy6hcv5g8/Screenshot%202014-01-21%2013.48.17.png I have an array of coordinates that are used to form the shape, which works fine for creating the actual shape. My first tactic was following this stackoverflow question: Core Text With Asymmetric Shape on iOS however I can only get it to draw the text at the bottom of the shape. Is there any way to

Getting CGRect for text in a UITextView for the purpose of highlighting with a CALayer

为君一笑 提交于 2019-12-03 20:06:26
I am trying to draw a transparent CALayer in a UITextView in order to highlight matched text in a search. I've figured out the correct way to do this, but still haven't found the correct coordinates. I need to find the origin of the text container. Right now, I get the textView's origin, and offset the layer's origin by that: NSRange match = [[[self textView]text]rangeOfString:@"predict the future"]; NSRange glyphRange = [manager glyphRangeForCharacterRange:match actualCharacterRange:NULL]; CGRect textRect = [manager boundingRectForGlyphRange:glyphRange inTextContainer:[[self textView