突然ですが、iPhone使ってます?
僕は毎日iPhone使ってますが、やっぱり面白いです。
アプリもいっぱいあるんで、毎日新しいアプリ入れたりして遊んでます。
やっぱりそんなアプリ作ってみたくなりますよね?
僕はなっちゃったので、レッツトライです!
まずは本買いました!
いろいろ、調べてみると、まずはこんな結果に。
・画面作成にInterface Builderは使わないほうがいい
・その方が後々、カスタマイズしやすい
なるほど。。。
これ前提で探した本がこれ。
全てInterface Builder使わずに画面作成する方法が(英語やけど)書いてあります
iPhone SDK Application Development: Building Applications for the AppStore
- 作者: Jonathan Zdziarski
- 出版社/メーカー: O'Reilly Media
- 発売日: 2009/02/06
- メディア: ペーパーバック
- 購入: 2人 クリック: 110回
- この商品を含むブログ (14件) を見る
Interface Buiderとの関係を断ち切る!
初めにInterface Builderとの関係を断ち切ります。
ResourcesフォルダにあるMainWindow.xibファイルを削除します。
次に、同じResourcesフォルダにあるInfo.plistファイルを開き
最終行の[Main nib file base name]の行を削除します。
最後にOther Sourcesフォルダにあるmain.mファイルを開きます。
UIApplicationMainメソッドを呼び出している行を、下記のように書き換えます。
int retVal = UIApplicationMain(argc, argv, nil, @"HelloWorldAppDelegate");
さぁ!ソースいじるぞ!!!
まずは、HelloWorldAppDelegate.hです。
#import <UIKit/UIKit.h> @interface MainView : UIView { UITextView *textView; } @end @interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; MainView *myMainView; } @property (nonatomic, retain) IBOutlet UIWindow *window; @end
次にHelloWorldAppDelegate.mです。
#import "HelloWorldAppDelegate.h" @implementation MainView - (id)initWithFrame:(CGRect) rect{ self = [super initWithFrame:rect]; if(self != nil){ textView = [[UITextView alloc] initWithFrame:rect]; textView.text = @"Hello World!"; [self addSubview:textView]; } return self; } -(void)dealloc{ [textView release]; [super dealloc]; } @end @implementation HelloWorldAppDelegate @synthesize window; - (void)applicationDidFinishLaunching:(UIApplication *)application { NSLog(@"start"); CGRect screenBounds = [[UIScreen mainScreen] applicationFrame]; CGRect windowBounds = screenBounds; windowBounds.origin.y = 0.0; self.window = [[UIWindow alloc] initWithFrame: screenBounds]; myMainView = [[MainView alloc] initWithFrame:windowBounds]; [window addSubview:myMainView]; // Override point for customization after application launch [window makeKeyAndVisible]; } - (void)dealloc { [myMainView release]; [window release]; [super dealloc]; } @end
これで「ビルドして実行」を選ぶとiPhoneシミュレータが立ち上がり
こんな画面がでれば成功ですね!
できたできた!ということで
iPhoneアプリでInterface Builder使わずに開発する際のチュートリアルにでもなれば幸いです。