我正在尝试制作水平滚动
这是我的代码
int frameSize = 140;
for (int i = 0; i < self.handArray.count + 10 ; i++)
{
CGRect frame;
frame.origin.x = i * frameSize;
frame.origin.y = 0;
frame.size = CGSizeMake(130, 130);
UIView *view = [[UIView alloc] initWithFrame:frame];
view.backgroundColor = [UIColor whiteColor];
UIImage *image;
// if (i == 0)
image = [UIImage imageNamed:@"halo.png"];
//else
// image = [UIImage imageWithContentsOfFile:[self.handArray objectAtIndex:i]];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setImage:[UIImage imageNamed:@"cross_red.png"] forState:UIControlStateNormal];
btn.tag = i;
btn.frame = CGRectMake(102, 0, 29, 29);
[btn addTarget:self action:@selector(deleteHandBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(10, 10, 120, 120);
[view addSubview:imageView];
if (i != 0)
[view addSubview:btn];
[self.handScrollView addSubview:view];
}
[self.handScrollView setContentSize:CGSizeMake(frameSize * (self.handArray.count + 10), self.handScrollView.frame.size.height)];
下面是图片
您可以看到我为特定区域定义了滚动视图,但图像分布在整个屏幕上。如何限制滚动视图的滚动宽度。