ios - 如何围绕列绘制轮廓?

标签 ios objective-c border

我想围绕一列画一个轮廓。这是我的应用程序的实际样子: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/

相关文章:

ios - 试图快速从 firebase 数据库中获取用户

iphone - 如何为所有子文件夹生成字符串

objective-c - 将 int 与存储在字典中的数字进行比较

html - 如何删除 CSS 边框内的空白?我希望文本周围的边框紧密

css - 使用整个图片作为 div 标签的边框

iphone - 事件从 iPhone 删除应用程序时

ios - iPhone 照片应用程序如何如此快速流畅地加载这么多图像?

Objective-C ARC 与 MRR : why the switch?

ios - 将标记项正确添加到 nsmutable 数组中

colors - 使用 docx4j 的蓝色表格边框