0

I am using AQGridView to create an image gallery that has about 21 items. I'd like to add a view that contains the app logo and name to the top of this list/scrollview so that users see it but as they scroll to look at images the view with name and logo scroll with it. Has anyone implemented something like this before?

Thanks to @skram I was able to add the logo, but now the image is block the first row of images.

Here is where I define the logo and add it to the 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];

then the images are loaded here:

- (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;
}

Here is a screenshot of the simulator:

enter image description here

mkral
  • 4,065
  • 4
  • 28
  • 53

1 Answers1

1

Yes. You can easily do this with addSubview:. On your AQGridView instance, add a UIImageView as a subview. AQGridView is nothing more than a subclassed UIScrollView, which you can use addSubview: on.

....
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];

Hope this helps.

EDIT: Editing Answer to reflect adding the logo as the first subview to the AQGridView so all images overlap the logo. Instead of using [_grid addSubview:logo], Assuming these are UIImageView's Use:

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

EDIT BY mkral

While skram version does work I wanted to mention that for my purposes the gridViewHeader is the best option, see code:

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]; 
mkral
  • 4,065
  • 4
  • 28
  • 53
skram
  • 5,314
  • 1
  • 22
  • 26
  • Ok great, it works but it's overlaying the images. Do you know where I need to set the offset? – mkral Jun 14 '12 at 16:36
  • You can use `insertSubview:belowSubview`. What this will do is add your logo as the very first object in the layer. Everything else after will be added on layers above: `[_grid insertSubview:logo belowSubview:(UIImageView*)[_grid.subviews objectAtIndex:0]]; Assuming it's a `UIImageView` – skram Jun 14 '12 at 16:43
  • I'm a little confused in your example aren't you saying to insert the logo imageview below the same logo imageview? – mkral Jun 14 '12 at 16:52
  • If you already have images in your scrollview, no. It's taking the first item thats already in your scroll view presumably one of the images. If this is not the case, everytime a new image is added you may have to do `sendSubviewToBack` – skram Jun 14 '12 at 16:58
  • Oh ok, well I am adding the logo subview first. Is there a delegate method for AQGridView like afterCellsLoaded or something. – mkral Jun 14 '12 at 17:00
  • If you're adding the logo first, then every added subview afterwards should be added above..weird Im not sure theres a method like that, I've never used it. – skram Jun 14 '12 at 17:04
  • Thanks for your time so far, could you take a look at my edit with code and image? – mkral Jun 14 '12 at 17:20