textkit

UIPageViewController/TextKit Reflowing Text on paging

人走茶凉 提交于 2019-12-03 17:10:44
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 backing text container by selecting the correct one out of the NLayoutManger's array of NSTextContainers.

UITextView - Highlight text with NSBackgroundColor - exclude line breaks

蹲街弑〆低调 提交于 2019-12-03 16:42:33
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) { textIsHighlited = NO; } }]; if (textIsHighlited) { [self.textStorage removeAttribute

Example of NSTextContainer with non regular shape?

China☆狼群 提交于 2019-12-03 08:10:36
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, 100)]; [layoutManager addTextContainer: textContainer]; BaseTextView *textView = [[BaseTextView alloc]

How to wrap text around attachments using iOS7 Text Kit?

扶醉桌前 提交于 2019-12-03 04:22:47
问题 I am using the new Text Kit API to add attachments to some attributed text: // create an attachment for each image NSTextAttachment* ta = [NSTextAttachment new]; ta.image = [UIImage imageNamed:@"imageName"]; // add to the attributed text string NSAttributedString* rep = [NSAttributedString attributedStringWithAttachment:ta]; [myAttributedTextString appendAttributedString:rep]; This works fine, I can see my image rendered in the output. However, I cannot find any way to specify the image

How to wrap text around attachments using iOS7 Text Kit?

假如想象 提交于 2019-12-02 17:38:13
I am using the new Text Kit API to add attachments to some attributed text: // create an attachment for each image NSTextAttachment* ta = [NSTextAttachment new]; ta.image = [UIImage imageNamed:@"imageName"]; // add to the attributed text string NSAttributedString* rep = [NSAttributedString attributedStringWithAttachment:ta]; [myAttributedTextString appendAttributedString:rep]; This works fine, I can see my image rendered in the output. However, I cannot find any way to specify the image alignment, or wrap text around the image. Any ideas? NOTE: Text attachments are different from exclusions

NSLayoutManager boundingRectForGlyphRange off by some Points

一笑奈何 提交于 2019-12-01 17:08:38
I want to "highlight" specific words in UITextView, not with a solid color (which would be possible via NSAttributedString ), but rather with a gradient and maybe some other fancy effects. Hence, I decided it would be necessary to manually create a view and overlay (or underlay) it using the bounding rectangles of the given text. To my surprise this turned out to be pretty straightforward. Example is inside a UIViewController, txtView being a UITextView connected as IBOutlet : override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() // Converting to NSString as I need a NSRange

NSLayoutManager boundingRectForGlyphRange off by some Points

邮差的信 提交于 2019-12-01 16:34:06
问题 I want to "highlight" specific words in UITextView, not with a solid color (which would be possible via NSAttributedString ), but rather with a gradient and maybe some other fancy effects. Hence, I decided it would be necessary to manually create a view and overlay (or underlay) it using the bounding rectangles of the given text. To my surprise this turned out to be pretty straightforward. Example is inside a UIViewController, txtView being a UITextView connected as IBOutlet : override func

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

拟墨画扇 提交于 2019-12-01 12:37:15
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.addAttributes([NSFontAttributeName: UIFont.italicSystemFont(ofSize: CGFloat(app_delegate.settings

iOS Drawing text in the centre of shapes

荒凉一梦 提交于 2019-12-01 04:17:31
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 centre the text vertically and horizontally? I then had a look at the new TextKit but I got stuck with

Animated UIImage in UITextView with TextKit

雨燕双飞 提交于 2019-11-30 17:21:13
I have a UIImage that contains multiple image frames and a duration which was sliced together from an animated GIF file. If I load the image in a UIWebView it will animate as expected, but I want to use a UITextView instead. The obvious choice is to use TextKit with a custom NSLayoutManger and many custom NSAttributedString attributes to achieve various drawing effects. I have a single UITextView that I'd like to give a NSAttributedString that contains NSTextAttachment s for all of the images I need to display inline. It's working fine except for when I load one of these animated UIImages ,