iPhoneSDKを理解する~Storyboradを使わない開発:Viewクラス追加~ [iOSプログラミング]
今回は、iPhoneSDKを理解する~Storyboradを使わない開発:Viewクラス追加~について。
概要としては、以下の通り。
XcodeのSample0005-1Groupを右クリックし、
「New File…」をクリックする。
iOSのCocoa Touchの項目一覧から
Objective-C classを選択し、
「Next」ボタンをクリックする。
下記条件でファイルを作成し、保存する。
Class:MainView
Subclass of:UIView
MainView.hを下記の通り修正する。
@interface MainView : UIView {
}
- (id)initWithFrame:(CGRect)frame;
- (void)dealloc;
@end
MainView.mを下記の通り修正する。
@implementation MainView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
詳細手順は、以下の通り。
1.XcodeのSample0005-1Groupを右クリックし、
「New File…」をクリックする。
2.iOSのCocoa Touchの項目一覧から
Objective-C classを選択し、
「Next」ボタンをクリックする。
3.下記条件でファイルを作成し、保存する。
Class:MainView
Subclass of:UIView
MainView.hとMainView.mが追加される。
4.MainView.hを下記の通り修正する。
@interface MainView : UIView {
}
- (id)initWithFrame:(CGRect)frame;
- (void)dealloc;
@end
5.MainView.mを下記の通り修正する。
@implementation MainView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
コメント 0