Re: How to draw background image in my app window
Re: How to draw background image in my app window
- Subject: Re: How to draw background image in my app window
- From: cocoa learner <email@hidden>
- Date: Sat, 30 May 2009 23:45:04 +0600
Yah Andy and Michael you all were right. But still I have some problem.1>.
While resizing the window Image is not getting resized.
2>. My controls (NSButton and NSTextField) are not visible after the
awakeFromNib call.
Here is modified code -
- (void) awakeFromNib
{
if (appWindow == NULL)
{
NSLog(@"AppController::awakeFromNib : appWindow is NULL");
}
else
{
NSLog(@"AppController::awakeFromNib : appWindow is not NULL");
if (winImageView == NULL)
{
NSLog(@"AppController::awakeFromNib : appWindow is NULL");
}
else
{
NSLog(@"AppController::awakeFromNib : appWindow is not NULL");
}
[ appWindow setContentView: winImageView];
}
}
- (id) init
{
[super init];
NSBundle *myBundle = [NSBundle mainBundle];
if (myBundle == NULL)
{
NSLog(@"AppController::init : myBundle is NULL");
}
else
{
NSLog(@"AppController::init : myBundle is not NULL");
}
NSString *path = [myBundle pathForResource:@"winImg" ofType:@"png"];
NSLog(@"AppController::init : Image file path : %@", path);
// winImageView is a data member of this class
winImageView = [[NSImageView alloc] init];
[winImageView setImage: [[NSImage alloc] initWithContentsOfFile: path]];
return self;
}
Regards
Cocoa.learner
On Sat, May 30, 2009 at 9:28 PM, Michael Vannorsdel <email@hidden>wrote:
> You're creating an NSImage and pretending it's an NSImageView which it's
> not. You'll need to create a new NSImageView and then the NSImage and set
> the image as the imageview's image.
>
>
>
> On May 30, 2009, at 8:27 AM, cocoa learner wrote:
>
> Thanx Nick for your reply.But in my window I am not getting the image I
>> want
>> to display. Here is my code -
>>
>> - (id) init
>>
>> {
>>
>> [super init];
>>
>> NSLog(@"AppController::init : Setting the windows content");
>>
>> NSBundle *myBundle = [NSBundle mainBundle];
>>
>> if (myBundle == NULL)
>>
>> {
>>
>> NSLog(@"AppController::init : myBundle is NULL");
>>
>> }
>>
>> else
>>
>> {
>>
>> NSLog(@"AppController::init : myBundle is not NULL");
>>
>> }
>>
>> NSString *path = [myBundle pathForResource:@"winImg" ofType:@"png"];
>>
>> NSLog(@"AppController::init : Image file path : %@", path);
>>
>> NSImageView *winContent = [[NSImage alloc] initWithContentsOfFile:path];
>>
>> [ appWindow setContentView: winContent];
>>
>> NSLog(@"AppController::init : The windows content has been set");
>>
>> return self;
>>
>> }
>>
>> I can see all the logs. But not the image in back ground of my app window.
>> Am I doing any thing wrong in this code?
>>
>> Regards
>> Cocoa.learner.
>>
>>
>> On Tue, May 26, 2009 at 11:12 PM, Nick Zitzmann <email@hidden>
>> wrote:
>>
>>
>>> On May 26, 2009, at 11:04 AM, cocoa learner wrote:
>>>
>>> How to draw background image in my app window?
>>>
>>>>
>>>>
>>> You could change the window's content view using -setContentView: to a
>>> view
>>> that will draw a background image, such as NSImageView... Of course, if
>>> you
>>> have any other controls in the content view that is being replaced, then
>>> they'll be lost.
>>>
>>> Nick Zitzmann
>>> <http://www.chronosnet.com/>
>>>
>>>
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>
>> 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
>>
>
> _______________________________________________
>
> 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
>
_______________________________________________
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