如何避免gridView现在覆盖我的uilabel的情况:iphone

时间:2012-07-11 15:58:32

标签: iphone gmgridview

我现在所拥有的是

View :
    1.UILabel :  show a text 
    2.A GMGridView : show a grid of views

代码是

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        gridViewHolder.itemSpacing      =   SPACING;
        gridViewHolder.dataSource       =   self;
        gridViewHolder.actionDelegate   =   self;
    }
#pragma mark - GMGridViewDataSource
- (CGSize)GMGridView:(GMGridView *)gridView sizeForItemsInInterfaceOrientation:(UIInterfaceOrientation)orientation {
    return CGSizeMake(WIDTH, HEIGT);     
}
- (NSInteger)numberOfItemsInGMGridView:(GMGridView *)gridView {
    return [needs count];
}
- (GMGridViewCell *)GMGridView:(GMGridView *)gridView cellForItemAtIndex:(NSInteger)index {
    cell                =   [gridView dequeueReusableCell];
    CGSize size         =   [self GMGridView:gridViewHolder sizeForItemsInInterfaceOrientation:UIInterfaceOrientationPortrait];

    if (!cell)
        cell            =   [[GMGridViewCell alloc] init];  

    UIView      *innerView                  =   [[UIView alloc] initWithFrame:CGRectMake(COOR_X, COOR_Y, size.width, size.height)];
    innerView.backgroundColor               =   [UIColor grayColor];

    cell.contentView                        =   innerView;
    return cell;
}

enter image description here

所以现在我可以成功地在gridview中显示一堆视图。但是,当我滚动网格视图时,网格视图的内容将覆盖标签。下面是图片,以便您现在可以看到我的情况 enter image description here

如何避免这种情况,以便每当我向上滚动gridview时,其内容都不会与我的uilabel重叠

2 个答案:

答案 0 :(得分:8)

试试这个:

gridview.clipsToBounds=TRUE;

答案 1 :(得分:0)

您可以使用视图上的insertSubview在标签下插入gridview。

[self.view insertSubview:gmGridView atIndex:0];