I have a window with a custom view object. The custom view displays an image file that is in my project folder by using an NSView class (my NSView class code is shown below).
Now I’m looking for a way to set the image for the custom view to a webpage image address instead of a local image file. Note that this is for a Mac application not a Touch application. As you can see from the implementation that I tried the NSURL approach but it didn’t work, it’s commented out in the code. So basically, how do I put a web image into a desktop window?
NSView header file:
#import <Cocoa/Cocoa.h>
@interface OurView : NSView {
NSImageView *picture;
}
@end
NSView m file:
#import "OurView.h"
@implementation OurView
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
NSRect rect = NSMakeRect(0, 0, 500, 500);
picture = [[NSImageView alloc] initWithFrame:rect];
[picture setImageScaling:NSScaleToFit];
[picture setImage:[NSImage imageNamed:@"earth.jpg"]];
//[picture setImage:[NSURL URLWithString:@"http://curious.astro.cornell.edu/images/xraysun.gif"]];
[self addSubview:picture];
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect {
// Drawing code here
}
@end
Try: