• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSTextContainer exclusionPaths not working on iOS without UITextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTextContainer exclusionPaths not working on iOS without UITextView


  • Subject: NSTextContainer exclusionPaths not working on iOS without UITextView
  • From: Steve Mills <email@hidden>
  • Date: Thu, 21 Sep 2017 08:04:32 -0500

Didn't work the first time I sent this, because something messed up and thought
the message was too large, when it's less than 2000 characters.

No bites on apple-dev.groups.io, so I'll try here.

I'm trying to use exclusionPaths for the first time and am not having any
success. For now, I'm just creating the stuff on the fly in my
drawLayer:inContext: method:. The string draws, but doesn't exclude any path no
matter what I set it to. I'm also not that familiar with the whole
NSTextStorage/NSLayoutManager/NSTextContainer family, other than using snippets
of code in the past, so it could be I'm doing something dumb. Any ideas?

BTW, if I instead install a UITextView and set its exclusionPaths, it works. So
does NSTextStorage not know enough to draw with the exclusionPaths, and I just
need to install text views for each one instead?

-(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)ctx
{
        if([layer.name isEqualToString:@"balloons"]) {
                UIGraphicsPushContext(ctx);

                CGRect box = CGRectMake(0, 0, 400, 400);
                NSTextStorage* storage = [[NSTextStorage alloc]
initWithString:@"I like little pigs who run and scurry away from the butcher,
because the butcher is carrying a large cleaver and wants to chop them up into
delicious sandwiches!" attributes:@{NSFontAttributeName:[UIFont
systemFontOfSize:36]}];
                UIBezierPath* bez = [UIBezierPath
bezierPathWithRect:CGRectMake(100, 100, 100, 100)];
                NSLayoutManager* lman = [NSLayoutManager new];

                [storage addLayoutManager:lman];

                NSTextContainer* cont = [[NSTextContainer alloc]
initWithSize:box.size];

                cont.exclusionPaths = @[bez];
                [lman addTextContainer:cont];

                // Trying different things to see if they make it work - nope.
                [lman textContainerChangedGeometry:cont];
                [lman invalidateLayoutForCharacterRange:NSMakeRange(0,
storage.length) actualCharacterRange:nil];

                [storage drawInRect:box];

                UIGraphicsPopContext();
        }
}

--
Steve Mills
Drummer, Mac geek

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSTextContainer exclusionPaths not working on iOS without UITextView
      • From: Aki Inoue <email@hidden>
  • Prev by Date: Re: Inserting a button into another application's toolbar
  • Next by Date: Re: NSTextContainer exclusionPaths not working on iOS without UITextView
  • Previous by thread: Re: Exception in IKImageBrowserView in macOS 10.13 GM
  • Next by thread: Re: NSTextContainer exclusionPaths not working on iOS without UITextView
  • Index(es):
    • Date
    • Thread