0
さて、私はMacでプログラミングする方法を学んでいます。私は答えを探しているのに飽き飽きしています。プログラムでWeb画像を読み込んでカスタムビューに表示するには?
まず、ウィンドウに2つのボタンをドラッグしました(イメージのロードとアンロード)。次に、私はカスタムビューアイテムをドラッグし、ここでは私がTest_Loading_ImagesAppDelegateで行ったことを実行します。 時間:その後
#import <Cocoa/Cocoa.h>
@interface Test_Loading_ImagesAppDelegate : NSView {
NSWindow *window;
IBOutlet NSView *mypicture;
}
- (IBAction)LoadImage: (id)sender;
- (IBAction)Unload: (id)sender;
@property (assign) IBOutlet NSWindow *window;
@end
、私は普通にInterface Builder上で物事をリンクしTest_Loading_ImagesAppDelegateを作りました。 メートル:事前に
#import "Test_Loading_ImagesAppDelegate.h"
@implementation Test_Loading_ImagesAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
}
-(IBAction)LoadImage: (id) sender {
NSURL *myurl;
NSImage *image;
NSData *myurldata;
myurl = [NSURL URLWithString:@"http://....jpg"];
myurldata = [NSData dataWithContentsOfURL:myurl];
image = [NSImage initWithData:myurldata];
[mypicture setImage: image];
}
-(IBAction)Unload: (id) sender {
//Well, still thinking how I'm going to do this, and I would like to make another question: If I dealloc the View or something else the image will disappear?
}
@end
感謝。