在UICollectionView的单元格之间绘制虚线

时间:2016-06-10 11:06:09

标签: ios objective-c uicollectionview core-graphics

我必须达到这样的目标(请查看附带的ScreenShot)。我想到的最好的解决方案是private void button1_Click(object sender, EventArgs e) { SqlCommand cmd = new SqlCommand("//Your Query//"); //SqlCommand cmd = new SqlCommand(); //cmd.CommandText = "GetSalesCrystalReport"; //cmd.CommandType = CommandType.StoredProcedure; //cmd.Parameters.AddWithValue("@ReferenceNo", txtReferenceNo.Text); DataTable dt1 = DataManager.GetDataTable(cmd); Sales objRpt3 = new Sales(); objRpt3.SetDataSource(dt1); objRpt3.PrintToPrinter(1, false, 0, 0); } 。我在单元格上创建了​​圆形边框,并在单元格上放了一个按钮。现在,对于虚线直线,我将UICollectionViewCAShapeLayer一起使用,并将该图层添加到我的BezierPath。问题来了,我没有看到任何虚线。这是我尝试过的。现在我有几个问题。在回答时请将我视为初学者。

1)为什么我的线条没有显示 2)如何计算两个单元格之间的宽度,现在我正在设置一个随机数 3)是否有任何其他方法可以更有效地解决此用例。

required

collectionview background with background color set to clear color

这是我到目前为止所取得的成就enter image description here

2 个答案:

答案 0 :(得分:10)

您好使用$preparedStatement->fetchColumn(); 并绘制函数。

screenshot

在路径https://github.com/arunpkumar92/OrderStatusCollectionView

上传的代码
UICollectionViewLayout

答案 1 :(得分:3)

  

为什么我的线条没有显示。

要让您的绘图可见,您必须将绘图代码直接添加到distance实例,而不是添加到UICollectionView属性。

backgroundView

这100%有效。使用[self.milestoneCollection.layer addSublayer:shapelayer]; 似乎是正确的做法,但他们可能会将其用于完全不同的东西。我怀疑backgroundView目前不可见(使用默认配置)或完全忽略我们的更改请求。

Lines_Drawn_Center_To_Center

  

如何计算两个单元格之间的宽度,现在我正在设置一个随机数。

backgroundView

-(void)getLineStartPoint:(CGPoint*)startPoint andEndPoint:(CGPoint*)endPoint fromCellAtIndexPath:(NSIndexPath*)fromIndexPath toCellAtIndexPath:(NSIndexPath*)toIndexPath { UICollectionViewLayoutAttributes* fromAttributes = [self.milestoneCollection layoutAttributesForItemAtIndexPath:fromIndexPath]; UICollectionViewLayoutAttributes* toAttributes = [self.milestoneCollection layoutAttributesForItemAtIndexPath:toIndexPath]; *startPoint = fromAttributes.center; *endPoint = toAttributes.center; } 在特定UICollectionViewLayoutAttributes处有关于cells, headers, footers, decorationViews的几何信息的100%功能丰富。为简单起见,我现在使用indexPath。我相信你需要在center属性中使用你的逻辑。

  

是否有其他方法可以更有效地解决此用例。

是的,总有两种方式。

  • 完成任务。
  • 完成任务正确

当然 RIGHT 根据可用的情况和时间而有所不同。

保持心情

  • 小心frame可用性,否则很容易崩溃。这是最简单的守卫形式 -

    indexPath
  • 此外,当您尝试滚动它(如果需要)时,会添加图层/路径 每次你创建一个单元格(这会导致黑暗的虚线由于 多次添加层次结构),你需要小心 当重用细胞时看看这个: -

Line_Drawn_Multiple_Times.png

那应该回答你所有的问题。最好的运气!!