Add a GMGridView to a subview so that it doesn't take all screen

151 Views Asked by At

I am trying to add a GMGridView to a subview in my nib file, but I can't seem to figure out how to do this because GMGridView keeps taking up all the space in my nib generated view, and covers everything else.

This is what I am trying (pasting just parts of code to make it more readable):

- (void)viewDidLoad {
    [super viewDidLoad];
    _gmGridView.mainSuperView = self.gridView;   
}

- (void)loadView {
    [super loadView];
    self.view.backgroundColor = [UIColor whiteColor];

    NSInteger spacing = INTERFACE_IS_PHONE ? 10 : 15;

    GMGridView *gmGridView = [[GMGridView alloc] initWithFrame:self.gridView.bounds];
    gmGridView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    gmGridView.backgroundColor = [UIColor clearColor];
    [self.gridView addSubview:gmGridView];
    _gmGridView = gmGridView;

    _gmGridView.style = GMGridViewStylePush;
    _gmGridView.itemSpacing = spacing;
    _gmGridView.minEdgeInsets = UIEdgeInsetsMake(spacing, spacing, spacing, spacing);
    _gmGridView.centerGrid = NO;
    _gmGridView.actionDelegate = self;
    _gmGridView.dataSource = self;

}

Is this the right approach, or should I create another nib with the GMGridView in it, and add that one to my subview?

Thanks in advance to anyone!

1

There are 1 best solutions below

0
On

You should make the following:

  • First make a UIView in your nib file with the dimensions you want the GridView be at.
  • Init your GMGridView with your UIView frame GMGridView *gmGridView = [[GMGridView alloc] initWithFrame:self.gridViewContainer.frame];
  • Then put this option _gmGridView.clipsToBounds = YES; , without this option the Cells will be floating outside the container view.

Hopes that's help.