Re: how do I put a subview in a superview with color
Re: how do I put a subview in a superview with color
- Subject: Re: how do I put a subview in a superview with color
- From: colo <email@hidden>
- Date: Thu, 30 Dec 2010 18:13:42 -0500
On Thu, Dec 30, 2010 at 5:32 PM, Alastair Houghton
<email@hidden> wrote:
> On 30 Dec 2010, at 22:22, colo wrote:
>
>> I was following the Chapter 17 Cocoa programming for osx 3rd ed
>> The code is below.
>> All I want to do for a working example is draw an NSView subview in
>> the superview.
>> And give it have a color and width height.
>>
>> I was trying all sorts of things. I can draw NSMakeRects in the drawRect method
>> But I just can't get it to draw another NSview for practice.
>> Or draw an NSMakeRect as a NSView.
>
> You don't "draw" an NSView. An NSView (or subclass) is either a subview of your view, or it isn't. And you mustn't add or remove subviews during your -drawRect: method; during drawing, the set of subviews really needs to remain stable in order for Cocoa's optimised drawing machinery to function correctly.
>
> Kind regards,
>
> Alastair.
>
> --
> http://alastairs-place.net
Thank you Alastair for those notes.
To update this and going from your notes.
I can get it to compile just fine now but I can't get the button to
show up at all.
Perhaps I am sending the addSubview to the incorrect place? NSView
*superview = [window contentView];
I thought contentView was the top.
@implementation WVShapesView
-(BOOL) isFlipped { return YES;}
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
NSView *superview = [window contentView];
NSRect frame = NSMakeRect(10, 10, 200, 100);
NSButton *button = [[NSButton alloc] initWithFrame:frame];
[button setTitle:@"arrrrggg"];
[superview addSubview:button];
[button release];
}
return self;
}
_______________________________________________
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