UIViewControllerを使わずにUIViewをInterface builderで作成する

1.UIViewを継承したクラスを作成
#import <UIKit/UIKit.h>

@interface UserView : UIView
{
    IBOutletUIView*    contentView;
    IBOutletUILabel*   userLabel;
    IBOutletUILabel*   telLabel;
}

@property (nonatomic, retain) IBOutletUIView*  contentView;
@property (nonatomic, retain) IBOutletUILabel* userLabel;
@property (nonatomic, retain) IBOutletUILabel* telLabel;

@end

#import "UserView.h"

@implementation UserView

@synthesize contentView, userLabel, telLabel;

- (void)_makeView
{
    [[NSBundlemainBundle] loadNibNamed:@"UserView"owner:selfoptions:nil];
    [selfaddSubview:contentView];        
}

- (id)init
{
    self = [superinit];
    if (self) {
        [self_makeView];
    }
    returnself;
}
- (id)initWithFrame:(CGRect)frame
{
    self = [superinitWithFrame:frame];
    if (self) {
        [self_makeView];
    }
    returnself;
}

- (void)dealloc
{
    [contentViewrelease];
    [userLabelrelease];
    [telLabelrelease];
    [superdealloc];
}

@end

2.Interface builderを使用してレイアウト作成
[New] -> [File] -> "User Interface"からEmptyを作成
名前はUserView(UserView.xibが生成される)
 - File's Owner
    - Custom Class : UserView

今回は表示名(userLabel)と電話番号(telLabel)を追加

3.IBOutletをひも付けを行う
メインのviewはcontentViewとひも付ける。直接UserView自身には設定できないみたい
あとはuserLabel, telLabelをひも付け

4.使ってみる①
ViewControllerでいつも通り使う事が可能
    UserView* userView = [[UserView alloc] initWithFrame:CGRectMake(0, 0, 320, 80)];
    [userView autorelease];
    [self.viewaddSubview:userView];

5.使ってみる②
ViewControllerのxibに追加する方法
 - UIViewをいつも通り追加して、Custom ClassをUserViewに変更
 - UserView.mに以下を追加
- (void)awakeFromNib
{
    [self_makeView];
}



ReactNativeでAndroid対応する話

前提 ReactNativeでiOS版のアプリをリリースしていて、Android版をリリースする話 トラブルシューティング Build.VERSION_CODES.Q が存在しないエラー compileSdkVersionを29以上にすると解決 メモリー足りないエラー Execu...