Skip to content

Instantly share code, notes, and snippets.

@tokorom
Created November 28, 2011 00:39
Show Gist options
  • Save tokorom/1398590 to your computer and use it in GitHub Desktop.
Save tokorom/1398590 to your computer and use it in GitHub Desktop.
ChameleonUIKitDemo
#import <Cocoa/Cocoa.h>
@class ChameleonAppDelegate;
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (retain) IBOutlet UIKitView* chameleonView;
@property (retain) ChameleonAppDelegate* chameleonApp;
@end
#import "AppDelegate.h"
#import "ChameleonAppDelegate.h"
@implementation AppDelegate
@synthesize chameleonView = chameleonView_;
@synthesize chameleonApp = chameleonApp_;
- (void)dealloc
{
self.chameleonView = nil;
self.chameleonApp = nil;
[super dealloc];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
self.chameleonApp = [[[ChameleonAppDelegate alloc] init] autorelease];
[self.chameleonView launchApplicationWithDelegate:self.chameleonApp afterDelay:1];
}
@end
@interface ChameleonAppDelegate : NSObject <UIApplicationDelegate>
@property (retain) UIWindow* window;
@property (retain) UIViewController* rootViewController;
@end
#import "ChameleonAppDelegate.h"
#import "RootViewController.h"
@synthesize window = window_;
@synthesize rootViewController = rootViewController_;
- (void)dealloc
{
self.window = nil;
self.rootViewController = nil;
[super dealloc];
}
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
self.window.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.rootViewController = [[[RootViewController alloc] init] autorelease];
self.rootViewController.view.frame = self.window.bounds;
self.rootViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.window addSubview:self.rootViewController.view];
[self.window makeKeyAndVisible];
return YES;
}
@end
#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#import <UIKit/UIKit.h>
#import <UIKit/UIKitView.h>
#endif
@interface RootViewController : UIViewController
@end
#import "RootViewController.h"
@implementation RootViewController
- (void)loadView
{
[super loadView];
// 背景色設定
self.view.backgroundColor = [UIColor whiteColor];
// UIImageViewを試用
UIImage* image = [UIImage imageNamed:@"mayuge_dog"];
UIImageView* imageView = [[[UIImageView alloc] initWithImage:image] autorelease];
imageView.frame = self.view.bounds;
imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
imageView.contentMode = UIViewContentModeScaleAspectFit;
[self.view addSubview:imageView];
// ボタンを試用
UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"WAN!" forState:UIControlStateNormal];
[button sizeToFit];
button.center = self.view.center;
button.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleBottomMargin;
[button addTarget:self
action:@selector(buttonDidPush)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
- (IBAction)buttonDidPush {
NSAlert* alert = [[[NSAlert alloc] init] autorelease];
[alert setMessageText:@"わん!"];
[alert addButtonWithTitle:@"OK"];
[alert runModal];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment