【发布时间】:2016-06-10 11:06:08
【问题描述】:
我必须实现这样的目标(请查看附加的屏幕截图)。我想到的最好的解决方案是UICollectionView。我沿着单元格创建了圆形边框并在单元格上放置了一个按钮。现在对于虚线直线,我使用了CAShapeLayer 和BezierPath,并将图层添加到我的collectionview background with background color set to clear color。问题来了,我没有看到任何虚线。这是我尝试过的。现在我有几个问题。回答时请把我当作初学者。
1) 为什么我的台词没有显示。
2) 如何计算两个单元格之间的宽度,我现在正在设置一个随机数。
3)有没有其他方法可以更有效地解决这个用例。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
UIBezierPath *borderPath;
CGFloat borderWidth;
KKCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"testCell" forIndexPath:indexPath];
borderPath = [UIBezierPath bezierPath];
[borderPath moveToPoint:CGPointMake(cell.frame.origin.x + cell.frame.size.width -1 , cell.frame.origin.y + 2)];
[borderPath addLineToPoint:CGPointMake(cell.frame.origin.x + cell.frame.size.width + 50, cell.frame.origin.y +2)];
borderWidth = 1.0;
[self dottedLineWithPath:borderPath withborderWidth:borderWidth];
return cell;
}
/** creating dotted line **/
- (void)dottedLineWithPath:(UIBezierPath *)path withborderWidth:(CGFloat)lineWidth
{
CAShapeLayer *shapelayer = [CAShapeLayer layer];
shapelayer.strokeStart = 0.0;
shapelayer.strokeColor = [UIColor blackColor].CGColor;
shapelayer.lineWidth = borderWidth;
shapelayer.lineJoin = kCALineJoinRound;
shapelayer.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithInt:1],[NSNumber numberWithInt:2 ], nil];
shapelayer.path = path.CGPath;
[self.milestoneCollection.backgroundView.layer addSublayer:shapelayer];
}
【问题讨论】:
-
集合视图为您提供什么好处?网格布局?
-
是的,这就是我使用它的原因。原因可能是将来圈数可能会增加或减少。所以只是为了避免返工。无论如何你的建议是什么。我愿意接受任何其他可能性。
-
按照复杂性和功能的顺序:首先,为所有图形使用图像并覆盖文本。然后使用布置在超级视图视图上的视图。然后是带有附件视图的集合视图。
-
看起来有点乏味,不是什么简单的方法:)
-
图像是一种简单的方法 - 编程并不容易,如果你只想简单地解决问题,那么你就做错了
标签: ios objective-c uicollectionview core-graphics