我使用uicollectionview来开发填字游戏,当我尝试填充黑色单元格时,我看不到边界线。 我的代码是:
[cell setBackgroundColor:[UIColor blackColor]];
[cell setFrame:CGRectInset(cell.frame, 3.0f, 3.0f)];``
[cell.layer setCornerRadius:3];
结果如下:
如何解决问题?
非常感谢
答案 0 :(得分:1)
您正在设置单元格的框架,方法是将该单元格的框架向下放置在左边3上,而在Y上放置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];
答案 1 :(得分:0)
这是我的代码:
-(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);
}
}