UICollectionView borderline不存在与黑色背景

问题描述:

我正在使用uicollectionview开发填字游戏,当我尝试填充黑色单元格时我看不到边框线。 我的代码是:UICollectionView borderline不存在与黑色背景

[cell setBackgroundColor:[UIColor blackColor]]; 
    [cell setFrame:CGRectInset(cell.frame, 3.0f, 3.0f)];`` 
    [cell.layer setCornerRadius:3]; 

这是结果:

enter image description here 如何解决这个问题呢?

非常感谢

你被放置下来,并在Y上留下的3 x和3,因为这条线的设置单元格的框架:

[cell setFrame:CGRectInset(cell.frame, 3.0f, 3.0f)]; 

也许你应该添加一个子视图是黑色的细胞,并为其分配这样

[view setFrame:CGRectMake(3,3, cell.frame.size.width-6, cell.frame.size.height-6)]; 

所以总的框架,我认为它会是这个样子:

UIView *view = [[UIView alloc]initWithFrame:CGRectMake(3,3, cell.frame.size.width-6, cell.frame.size.height-6)]; 
[view setBackgroundColor:[UIColor blackColor]]; 
[view.layer setCornerRadius:3]; 
[cell addSubview:view]; 
+0

我只是尝试这种解决方案和工作的第一次,但问题是,如果我点击编号为细胞,我使用以下代码重新加载了uicollecollection视图: [collectionView performBatchUpdates:^ {collectionView reloadSections:[NSIndexSet index SetWithIndex:0]]; } completion:nil]; 我不这样做,但黑色细胞增加。我已经放了很多日志,并且数组读取的很好。 – user3576455 2015-03-20 09:01:27

+0

我发布了代码 – user3576455 2015-03-20 09:05:27

+0

我看到了你的代码,但我想我错过了它的一部分,因为你在哪里以及如何创建collectionview单元格?你对每种类型的细胞使用不同的细胞标识符吗?它看起来当我收集视图重新加载时,他使用已存在的单元格,但将它们混合一点。 – Sanne 2015-03-21 11:30:35

这是我的代码:

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if ([strArrayLabel isEqualToString:@"black"]) 
     { 
      UIView *view = [[UIView alloc]initWithFrame:CGRectMake(3,3, cell.frame.size.width-6, cell.frame.size.height-6)]; 
      [view setBackgroundColor:[UIColor blackColor]]; 
      [view.layer setCornerRadius:3]; 
      [cell addSubview:view]; 

      NSLog(@"black"); 
     } 
     else if ([strArrayLabel isEqualToString:@"blank"]) 
     { 
      [cell setBackgroundColor:[UIColor whiteColor]]; 
      [[cell myLabel]setText:number]; 
      [[cell letter]setText:letter]; 

      NSLog(@"blank"); 
     } 
     else 
     { 

      [cell setBackgroundColor:[UIColor whiteColor]]; 
      [[cell myLabel]setText:number]; 
      [[cell letter]setText:letter]; 

      NSLog(@"no black no blank %@, <%@>", number, letter); 
     } 
} 

enter image description here

enter image description here