水平スクロールビューの画像に役立つ場合があります。
int scrollWidth = 180;
scrollview.contentSize = CGSizeMake(scrollWidth,110);
int xOffset = 4;
for(int i = 0; i < [imgnamearr count]; ++i)
{
UIImageView *img = [[UIImageView alloc] init];
img.layer.masksToBounds = YES;
img.frame = CGRectMake(5+xOffset,1, 145, 110);
scrollview.contentSize = CGSizeMake(scrollWidth+xOffset,115);
[img addSubview:[UIImage imageNamed:[imgnamearr objectAtIndex:i]]];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(5+xOffset,0, 160, 110);
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
button.accessibilityIdentifier =[imgarr objectAtIndex:i];
[scrollview addSubview:img];
[scrollview addSubview:button];
scrollview.contentSize = CGSizeMake(scrollWidth+xOffset,115);
xOffset += 157;
}
- (IBAction)buttonClicked:(UIButton *)sender {
UIImageView *bigimg = [[UIImageView alloc] init];
bigimg.layer.masksToBounds = YES;
bigimg.frame = CGRectMake(0,0, 200, 200);
[bigimg addSubview:[UIImage imageNamed:sender.accessibilityIdentifier]];
[self.view addSubview:bigimg];
}
編集2:
-(void)Setthewholeview{
int row = 0;
int column = 0;
for(int i = 0; i < [imagearry count]; ++i)
{
UIView *uview =[[UIView alloc]initWithFrame:CGRectMake(column*155+5, row*126, 155, 125)];
uview.layer.masksToBounds=YES;
uview.backgroundColor = [UIColor whiteColor];
UIImageView *detailback =[[UIImageView alloc] initWithFrame:CGRectMake(0,72,52,52)];
detailback.image=[[UIImage alloc]init];
detailback.image = [UIImage imageNamed:@"abc.png"];
[uview addSubview:detailback];
[detailback release];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(column*155+5, row*126, 155, 125);
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
button.tag = [[arrayname objectAtIndex:i]intValue];
if (column == 1) // here set column which you want. If you wnat 2 column then set 1 here.
{
column = 0;
row++;
} else
{
column++;
}
[self.scrollview addSubview:uview];
[self.scrollview addSubview:button];
}
[self.scrollview setContentSize:CGSizeMake(320, (row+1) * 130)];
}