的UITableView与卡卡和列表中 - iOS设备斯威夫特
我试图创建一个自定义UITableView
我的内容,以显示卡内,这样的事情:的UITableView与卡卡和列表中 - iOS设备斯威夫特
我已经一类CardView到用我的影子创造我的名片,但是我没有成功地正确使用它来获得我正在寻找的东西。
也许最好的方法是自定义部分并在其上应用我的CardView。
你能帮我吗?
谢谢!
使用的UITableView内tableviewcell。
1.创建UITableView1-> UITableviewCell1-> UIView-> UITableView2-> UITableviewCell2
2.设置UITableview2代表在UITableviewCell1
3.Reload UITableView2内部UITableView1 cellforRow
步骤2 内部UITableviewCell1 override func awakeFromNib() { //UITableView2 Delegates self.tableView2.delegate = self self.tableView2.dataSource = self super.awakeFromNib() }
您可以详细介绍第二步:在UITableviewCell1中设置UITableviewCell2委托?由于 – vermotr
对不起集UITableview2代表在UITableviewCell1'override FUNC awakeFromNib(){// 代表的TableView self.tableView2.delegate =自 self.tableView2.dataSource =自 super.awakeFromNib() }” – Sabarinathan
使用的UICollectionView,看看下面的教程,你想要做什么:
http://www.phillfarrugia.com/2017/06/19/rebuilding-the-new-app-store-app-today-view/
对于这个问题,只需将tableView:willDisplayCell:forRowAtIndexPath:
委托方法与f随着代码(简单的复制/粘贴应该工作),它也应该适用于分组表。我评论你应该在哪里设置边框的宽度和颜色。
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:@selector(tintColor)]) {
CGFloat cornerRadius = 5.f;
cell.backgroundColor = UIColor.clearColor;
CAShapeLayer *layer = [[CAShapeLayer alloc] init];
CGMutablePathRef pathRef = CGPathCreateMutable();
CGRect bounds = CGRectInset(cell.bounds, 10, 0);
BOOL addLine = NO;
if (indexPath.row == 0 && indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
CGPathAddRoundedRect(pathRef, nil, bounds, cornerRadius, cornerRadius);
} else if (indexPath.row == 0) {
CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds));
CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius);
CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds));
addLine = YES;
} else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds));
CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius);
CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds));
} else {
CGPathAddRect(pathRef, nil, bounds);
addLine = YES;
}
layer.path = pathRef;
CFRelease(pathRef);
//set the border color
layer.strokeColor = [UIColor lightGrayColor].CGColor;
//set the border width
layer.lineWidth = 1;
layer.fillColor = [UIColor colorWithWhite:1.f alpha:1.0f].CGColor;
if (addLine == YES) {
CALayer *lineLayer = [[CALayer alloc] init];
CGFloat lineHeight = (1.f/[UIScreen mainScreen].scale);
lineLayer.frame = CGRectMake(CGRectGetMinX(bounds), bounds.size.height-lineHeight, bounds.size.width, lineHeight);
lineLayer.backgroundColor = tableView.separatorColor.CGColor;
[layer addSublayer:lineLayer];
}
UIView *testView = [[UIView alloc] initWithFrame:bounds];
[testView.layer insertSublayer:layer atIndex:0];
testView.backgroundColor = UIColor.clearColor;
cell.backgroundView = testView;
}
}
还有,记得设置表没有在界面生成器的分离特性,(这是在默认情况下单线),如果要创建表编程,你应该设置这样
财产tableView.separatorStyle = UITableViewCellSeparatorStyleNone
代码: https://drive.google.com/file/d/0BwYZPQSG7kikbVpUZklGSWFwMTA/view?usp=sharing
有限公司你是否添加了一些代码来显示你所尝试的? –
您可以添加阴影图像作为单元格的背景 – iPatel