UITableViewCells之间的间距 [英] spacing between UITableViewCells
问题描述
我正在使用自定义笔尖。我知道使用UITableViewController。我想我会使用分隔符的样式,但它没有达到效果。我徘徊了几个小时,找不到一个简单的教程,这是有道理的!有人可以解释他们是如何使用swift的应用程序?谢谢!
使用Swift 2,您可以以这种方式在UITableViewCells之间间隔:
在您的TableViewController中复制:
//在这种情况下,我返回140.0。您可以根据单元格更改此值
覆盖func tableView(tableView:UITableView,heightForRowAtIndexPath indexPath:NSIndexPath) - > CGFloat {
return 140.0
}
覆盖func tableView(tableView:UITableView,willDisplayCell单元格:UITableViewCell,forRowAtIndexPath indexPath:NSIndexPath){
单元格。 contentView.backgroundColor = UIColor.clearColor()
let whiteRoundedView:UIView = UIView(frame:CGRectMake(0,10,self.view.frame.size.width,120))
whiteRoundedView.layer.backgroundColor = CGColorCreate(CGColorSpaceCreateDeviceRGB(),[1.0,1.0,1.0,1.0])
whiteRoundedView.layer.masksToBounds = false
whiteRoundedView.layer.cornerRadius = 2.0
whiteRoundedView.layer.shadowOffset = CGSizeMake(-1,1)
whiteRoundedView.layer.shadowOpacity = 0.2
cell.contentView.addSubview(whiteRoundedView)
cell.contentView.sendSubviewToBack (whiteRoundedView)
}
这是结果:
I am creating a ios app in swift and want to add spacing between cells like Facebook (pic bellow).
I am using a custom nib for the posts. I know to use UITableViewController. I figure I would use a separator style but it does not achieve the effect. I goggled around for hours and can't find a single tutorial in swift that makes sense! could some one explain how they did it in there app using swift? thanks!
With Swift 2 you can do spacing between UITableViewCells in this way:
In your TableViewController copy this:
// In this case I returning 140.0. You can change this value depending of your cell
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 140.0
}
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
cell.contentView.backgroundColor = UIColor.clearColor()
let whiteRoundedView : UIView = UIView(frame: CGRectMake(0, 10, self.view.frame.size.width, 120))
whiteRoundedView.layer.backgroundColor = CGColorCreate(CGColorSpaceCreateDeviceRGB(), [1.0, 1.0, 1.0, 1.0])
whiteRoundedView.layer.masksToBounds = false
whiteRoundedView.layer.cornerRadius = 2.0
whiteRoundedView.layer.shadowOffset = CGSizeMake(-1, 1)
whiteRoundedView.layer.shadowOpacity = 0.2
cell.contentView.addSubview(whiteRoundedView)
cell.contentView.sendSubviewToBack(whiteRoundedView)
}
This is the result:
这篇关于UITableViewCells之间的间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!