我想围绕一列画一个轮廓。这是我的应用程序的实际样子:https://gyazo.com/80dffe6a153e82565a610222a43e0c11
所以白色的柱子代表我们实际所在的那一天。但我真的不想那样做。
实际上我是这样做的:
if(column == _intOfTheDay){ //intOfTheDay represent the day one where we are actually
cell.backgroundColor = [[UIColor whiteColor]colorWithAlphaComponent:0.95];
}
我试过这样的方法来接近我想要的结果:
if(column == _intOfTheDay){
cell.layer.borderWidth = 5.0f;
cell.layer.borderColor = [UIColor redColor].CGColor;
}
但这里的问题(没有由于 UICollectionView
引起的所有错误)是它在每个单元格周围绘制了一个矩形。我想要的是只绘制一个矩形但围绕所有列。
我该如何处理?
我们将不胜感激,在此先致谢。
最佳答案
如果你不想子类化 UICollectionViewCell 然后使用这个:
float borderWidth = 5.0;
CALayer *leftBorder = [CALayer new];
leftBorder.frame = CGRectMake(0.0, 0.0, borderWidth, cell.frame.size.height);
leftBorder.backgroundColor = [UIColor redColor].CGColor;
[cell.layer addSublayer:leftBorder];
CALayer *rightBorder = [CALayer new];
rightBorder.frame = CGRectMake(cell.frame.size.width - borderWidth, 0.0, borderWidth, cell.frame.size.height);
rightBorder.backgroundColor = [UIColor redColor].CGColor;
[cell.layer addSublayer:rightBorder];
关于ios - 如何围绕列绘制轮廓?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36740568/