UIView をカスタマイズしました
@implementation PaiLifePageDetail
@synthesize pageIndex = _pageIndex;
#define MARGINTOTOP 200.0
#define MARGINTOLEFT 20.0
#define WIDTH 120.0
#define HEIGHT 150.0
- (id) initWithDataSource : (NSArray *) dataSource
{
self = [super init];
if (self)
{
if (dataSource)
{
for (PaiLifeCustomImageView *imageView in dataSource)
{
//page 1 line 1
if (_pageIndex == 1)
{
if ([imageView.location isEqualToString:@"r11"])
{
imageView.frame = CGRectMake(MARGINTOLEFT, MARGINTOTOP, WIDTH, HEIGHT * 2);
[self addSubview:imageView];
}
else if ([imageView.location isEqualToString:@"r12"])
{
imageView.frame = CGRectMake(MARGINTOLEFT + WIDTH + 20, MARGINTOTOP, WIDTH, HEIGHT);
[self addSubview:imageView];
}
}
//not page 1 line 1
else
{
if ([imageView.location isEqualToString:@"r11"])
{
imageView.frame = CGRectMake(MARGINTOLEFT, MARGINTOTOP, WIDTH, HEIGHT);
[self addSubview:imageView];
}
else if ([imageView.location isEqualToString:@"r12"])
{
imageView.frame = CGRectMake(MARGINTOLEFT + WIDTH + 20, MARGINTOTOP, WIDTH, HEIGHT);
[self addSubview:imageView];
}
else if ([imageView.location isEqualToString:@"r13"])
{
imageView.frame = CGRectMake(MARGINTOLEFT + (WIDTH + 20) * 2, MARGINTOTOP, WIDTH, HEIGHT);
[self addSubview:imageView];
}
}
// line 2
if ([imageView.location isEqualToString:@"r21"])
{
imageView.frame = CGRectMake(MARGINTOLEFT, MARGINTOTOP + HEIGHT + 20, WIDTH, HEIGHT);
[self addSubview:imageView];
}
else if ([imageView.location isEqualToString:@"r22"])
{
imageView.frame = CGRectMake(MARGINTOLEFT + WIDTH + 20, MARGINTOTOP + HEIGHT + 20, WIDTH, HEIGHT);
[self addSubview:imageView];
}
else if ([imageView.location isEqualToString:@"r23"])
{
imageView.frame = CGRectMake(MARGINTOLEFT + (WIDTH + 20) * 2, MARGINTOTOP + HEIGHT + 20, WIDTH, HEIGHT);
[self addSubview:imageView];
}
// line 3
if ([imageView.location isEqualToString:@"r31"])
{
imageView.frame = CGRectMake(MARGINTOLEFT, MARGINTOTOP + (HEIGHT + 20) * 2, WIDTH, HEIGHT);
[self addSubview:imageView];
}
else if ([imageView.location isEqualToString:@"r32"])
{
imageView.frame = CGRectMake(MARGINTOLEFT + WIDTH + 20, MARGINTOTOP + (HEIGHT + 20) * 2, WIDTH, HEIGHT);
[self addSubview:imageView];
}
else if ([imageView.location isEqualToString:@"r33"])
{
imageView.frame = CGRectMake(MARGINTOLEFT + (WIDTH + 20) * 2, MARGINTOTOP + (HEIGHT + 20) * 2, WIDTH, HEIGHT);
[self addSubview:imageView];
}
}
}
}
[self setNeedsDisplay];
return self;
}
@end
そしてこれが私の見解です
implementation PaiLifeViewController
@synthesize detail = _detail;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIImage *i = [UIImage imageNamed:@"menu_patcode_normal"];
PaiLifeCustomImageView *c1 = [[PaiLifeCustomImageView alloc] initWithImage:i];
c1.location = @"r11";
PaiLifeCustomImageView *c2 = [[PaiLifeCustomImageView alloc] initWithImage:i];
c2.location = @"r12";
PaiLifeCustomImageView *c4 = [[PaiLifeCustomImageView alloc] initWithImage:i];
c4.location = @"r21";
PaiLifeCustomImageView *c5 = [[PaiLifeCustomImageView alloc] initWithImage:i];
c5.location = @"r22";
PaiLifeCustomImageView *c6 = [[PaiLifeCustomImageView alloc] initWithImage:i];
c6.location = @"r23";
PaiLifeCustomImageView *c7 = [[PaiLifeCustomImageView alloc] initWithImage:i];
c7.location = @"r31";
PaiLifeCustomImageView *c8 = [[PaiLifeCustomImageView alloc] initWithImage:i];
c8.location = @"r32";
PaiLifeCustomImageView *c9 = [[PaiLifeCustomImageView alloc] initWithImage:i];
c9.location = @"r33";
NSArray *c = [[NSArray alloc] initWithObjects:c1,c2,c4,c5,c6,c7,c8,c9, nil];
//PaiLifePageDetail *pagec
_detail.pageIndex = 1;
_detail= [[PaiLifePageDetail alloc] initWithDataSource:c];
[_detail awakeFromNib];
}
@end
しかし、それは表示されません。理由がわかりません。これを手伝ってください。ありがとうございました。