2011年6月5日日曜日

Xcode: iPhoneでhtmlを扱う





htmlAppDelegate.h
#import <UIKit/UIKit.h>

@interface htmlAppDelegate : NSObject  {
    UIWindow *window;
 UIWebView *webView;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UIWebView *webView;

@end


htmlAppDelegate.m
#import "htmlAppDelegate.h"

@implementation htmlAppDelegate

@synthesize window;
@synthesize webView;

#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
    // Override point for customization after application launch.
    
    [self.window makeKeyAndVisible];
 
 NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:NO];
 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];
 
    
    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {

}


- (void)applicationDidEnterBackground:(UIApplication *)application {

}


- (void)applicationWillEnterForeground:(UIApplication *)application {

}


- (void)applicationDidBecomeActive:(UIApplication *)application {

}


- (void)applicationWillTerminate:(UIApplication *)application {

}


#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {

}


- (void)dealloc {
    [window release];
 [webView release];
    [super dealloc];
}


@end


index.html
<!DOCTYPE html>

<html lang="ja">
 
 <head>
  <meta http-equiv="Content-Type" content="text/html; charcet=UTF-8" />
  
  <link rel="stylesheet" href="index.css" />
  <script type="text/javascript" src="index.js" />
  
 </head>
 
 <body>
  
  <h1>Don't touch</h1>
  
  <button onclick="button()">button</button>
  
 </body>
</html>

index.js
function button(){

 alert("Bang" + "!!!");
}

index.css
h1 {
 color : #ff9900;
 }

参考

YouTube - How to build iPhone App with HTML5/CSS/JavaScript
http://www.youtube.com/watch?v=L28lGkoSQ2c&hd=1


0 コメント: