• 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
Re: Drawing shadows under views SOLVED
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drawing shadows under views SOLVED


  • Subject: Re: Drawing shadows under views SOLVED
  • From: Jeremy Dronfield <email@hidden>
  • Date: Wed, 18 Feb 2004 12:06:24 +0000

Thanks to all who've contributed. The prototype solution is detailed below for the record. I've yet to do the work to create the shadow only when a text view is clicked on. As it is, it just creates a text view sized for the text it contains and puts a grey outline round it and a shadow behind it. I'd appreciate any comments on my implementation. (I know it's missing the saving and resetting of graphics context - I did say it's only a prototype. The important point is getting the shadow under the text view.)

------------------------------------
@interface SKTemplateView : NSView
{
NSRect shadowRect;
}
- (NSRect)shadowRect;
- (void)setShadowRect:(NSRect)rect;
@end
------------------------------------
#import "SKTemplateView.h"
#import <AppKit/NSGraphicsContext.h>

@implementation SKTemplateView

- (id)initWithFrame:(NSRect)frameRect
{
if ((self = [super initWithFrame:frameRect]) != nil) {
}
return self;
}

- (void)drawRect:(NSRect)rect
{
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:[self shadowRect]];
[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];
}

- (NSRect)shadowRect {
return shadowRect;
}

- (void)setShadowRect:(NSRect)rect {
shadowRect = rect;
[self setNeedsDisplay:YES];
}
@end
------------------------------------
@implementation myControllerClass

- (void)setupTemplateView
{
//<snip> code here to alloc an attributed string called yearString to go in the textview

NSTextView *yearField = [[NSTextView alloc] initWithFrame:NSMakeRect(10.0, 10.0, [yearString size].width + 10, [yearString size].height)];
[yearField setDelegate:self];
[yearField setUsesFontPanel:YES];
[yearField insertText:yearString];

[templateView addSubview:yearField];
[templateView setShadowRect:[yearField frame]];

[yearString release];
[yearField release];
}
@end

-Jeremy

========================================
email@hidden

theLocustFarm.net:
- fractious fiction at http://freespace.virgin.net/jeremy.dronfield
========================================
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Drawing shadows under views (From: Patrick Machielse <email@hidden>)
 >Re: Drawing shadows under views (From: Jeremy Dronfield <email@hidden>)

  • Prev by Date: Re: Apps whitout nib
  • Next by Date: About the mysterious initWithBytes:length:encoding: NSString method
  • Previous by thread: Re: Drawing shadows under views
  • Next by thread: iTunes like 'diamond' progress indicator
  • Index(es):
    • Date
    • Thread