将View添加到AQGridView ScrollView的顶部

时间:2012-06-14 16:21:23

标签: iphone ios aqgridview

我正在使用AQGridView创建一个包含大约21个项目的图库。我想在此列表/滚动视图的顶部添加一个包含应用程序徽标和名称的视图,以便用户可以看到它,但是当它们滚动查看图像时,带有名称和徽标的视图会随之滚动。有没有人之前实现过这样的东西?

感谢@skram我能够添加徽标,但现在图像阻挡了第一行图像。

我在这里定义徽标并将其添加到gridView:

 self.gridView = [[AQGridView alloc] initWithFrame:CGRectMake(0, 0, 320, 367)];
        UIImageView *logo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"paramythLogoTest.png"]];
        [logo setFrame:CGRectMake(0,0,logo.frame.size.width,logo.frame.size.height)]; 
        [gridView addSubview:logo];
        self.gridView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
        self.gridView.autoresizesSubviews = YES;
        self.gridView.delegate = self;
        self.gridView.dataSource = self;



        [self.view addSubview:gridView];


        [self.gridView reloadData];

然后在这里加载图像:

- (AQGridViewCell *) gridView: (AQGridView *) aGridView cellForItemAtIndex: (NSUInteger) index
{
static NSString * PlainCellIdentifier = @"PlainCellIdentifier";

GridViewCell * cell = (GridViewCell *)[aGridView dequeueReusableCellWithIdentifier:@"PlainCellIdentifier"];

if ( cell == nil )
{
    cell = [[GridViewCell alloc] initWithFrame: CGRectMake(3.333, 3.333, 100, 100)
                               reuseIdentifier: PlainCellIdentifier];
}
NSString *stringURL = [[featuredStories objectAtIndex:index] objectAtIndex:1];

NSURL *url = [NSURL URLWithString:stringURL];
[cell.imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"example0.png"]];
cell.storyID = [[featuredStories objectAtIndex:index] objectAtIndex:0];\

return cell;
}

以下是模拟器的屏幕截图:

enter image description here

1 个答案:

答案 0 :(得分:1)

是。您可以使用addSubview:轻松完成此操作。在AQGridView实例上,添加UIImageView作为子视图。 AQGridView只不过是一个子类UIScrollView,您可以使用addSubview:

....
AQGridView *_grid;
....
UIImageView *logo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo.png"]];
[logo setFrame:CGRectMake(0,0,logo.frame.size.width,logo.frame.size.height)]; // Set the Frame's position on where you want it in the grid.
[_grid addSubview:logo];

希望这有帮助。

编辑:编辑答案以反映将徽标添加为AQGridView的第一个子视图,以便所有图像与徽标重叠。而不是使用[_grid addSubview:logo],假设这些是UIImageView的使用:

[_grid insertSubview:logo belowSubview:(UIImageView*)[_grid.subviews objectAtIndex:0]];

编辑mkral

虽然skram版本确实有用,但我想提一下,为了我的目的,gridViewHeader是最好的选择,请参阅代码:

UIImageView *logo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"paramythLogoTest.png"]];
[logo setFrame:CGRectMake(0,0,logo.frame.size.width,logo.frame.size.height)]; 
[gridView setGridHeaderView:logo];