페이지

2017년 3월 30일 목요일

iOS Creating Custom View

Creating MyView

1. Creating MyView Class

@interface MyView : UIView

@property(nonatomic,strong) UIView* contentView;

@property(nonatomic,strong) NSBundle* bundle;

@end





#import “MyView.h”

@implementation MyView

- (instancetype)initWithCoder:(NSCoder *)aDecoder{

    self = [super initWithCoder:aDecoder];

    if( self ){

        self.bundle = [NSBundle bundleForClass:[self class]];

        if (self.subviews.count == 0) {

            self.contentView = [[self.bundle loadNibNamed:NSStringFromClass([self class]) owner:self options:nil] objectAtIndex:0];

            [self addSubview: self.contentView];

            self.contentView.frame = self.bounds;

        }

    }

    return self;

}



@end



2. Creating MyView.nib

place "MyView" in the Class field of the File's Owner.



댓글 없음:

댓글 쓰기