• 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
Shadowed text view
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Shadowed text view


  • Subject: Shadowed text view
  • From: Eamon Ford <email@hidden>
  • Date: Mon, 12 Dec 2005 15:50:28 -0800

Hey all,

I'm trying to make a shadowed text view like in Address Book and iCal, and I've succeeded in making the shadow and gray outline, but what would be the best way to draw the text in the right place and highlight it when it's selected?

Here's my drawRect: method (most of this code is from Jeremy Dronfield):


- (void)drawRect:(NSRect)aRect
{
NSTextView * textView = [controller textView];

NSRange charRange = NSMakeRange(0, [[[textView textStorage] characters] count]);
NSRange glyphRange = [[textView layoutManager] glyphRangeForCharacterRange:charRange actualCharacterRange:nil];
NSRect rect = [[textView layoutManager] boundingRectForGlyphRange:glyphRange inTextContainer:[textView textContainer]];


NSColor *backgroundColor = [NSColor whiteColor];
[backgroundColor set];

NSRectFill([self bounds]);


NSColor *fillColor = [NSColor whiteColor];
NSColor *outlineColor = [NSColor grayColor];

NSShadow *viewShadow = [[NSShadow alloc] init];
[viewShadow setShadowOffset:NSMakeSize(3.5, -3.5)];
[viewShadow setShadowBlurRadius:6.5];

[fillColor setFill];
[outlineColor setStroke];

NSBezierPath *outline = [NSBezierPath bezierPathWithRect:rect];
[outline setLineWidth:1.0];
[outline setLineJoinStyle:NSMiterLineJoinStyle];
[outline stroke];
[viewShadow set];
[outline fill]; // <- important to put the shadow on the fill, not the stroke

[viewShadow release];
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: Shadowed text view
      • From: Todd Ransom <email@hidden>
  • Prev by Date: Re: NSObject Exercise comments?
  • Next by Date: Re: Ignore hide messages sent to my application?
  • Previous by thread: Does a given locale use a 12 or 24-hour clock? (Re: 24-hour default)
  • Next by thread: Re: Shadowed text view
  • Index(es):
    • Date
    • Thread