将保证金添加到UITableViewCell [英] Adding Margin to UITableViewCell

查看:119
本文介绍了将保证金添加到UITableViewCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力实现一个我在草图上嘲笑的观点。我在Android上复制了它,因为我在那个平台上真的很棒。我在iOS上很好,但UI是我的弱点。

I am trying to achieve a view I mocked out on sketch. I've replicated it on Android cause I'm really good on that platform. I'm good on iOS, but the UI is kind of my weak point.

我扩展了 UIViewController 并且在我的StoryBoard上有顶部是视图和底部一个tableview。我遇到的问题是将 UITableViewCell 集中在应用程序本身。以下是我尝试过的解决方案。但是,它只是把它全部挤到了顶端。 NB。我使用 UIView UITableViewCell中绘制那些微小的线条

I extended a UIViewController and on my StoryBoard have the top to be a view and the bottom a tableview. The problem I'm having is centering the UITableViewCell to look like that in the app itself. Below is the solution I've tried. But, it just squeeze it all to the top. NB. I use UIView to draw those Tiny Lines in the UITableViewCell

func configureTableView() {
    //First One I tried then later commented it out
    loanStateTable.rowHeight = UITableViewAutomaticDimension
    loanStateTable.scrollToNearestSelectedRowAtScrollPosition(UITableViewScrollPosition.Middle, animated: true)

    //Second One I tried
    var edgeInset = UIEdgeInsets(top: 16, left: 16, bottom: 0, right: 16)
    loanStateTable.contentInset = edgeInset
}

故事板视图

任何帮助将不胜感激。谢谢

Any help would be appreciated. Thanks

输出:

推荐答案

保持原样。不要试图插入整个TableView。改为在TableViewCell中创建容器视图:

Leave everything as it is. Don't try to inset your whole TableView. Create a container View inside your TableViewCell instead:

设置行高:

此外在代码中:

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return 160.0
}

指定边缘的正确距离:

Specify the right distance to the edges:

现在添加元素并指定约束:

Now add the elements and specify the constraints as well:




不要忘记设置cellIdentifier:

Don't forget to set the cellIdentifier:

模拟器中的结果:

如果你想深入了解它:我已将其作为github项目上传

If you want to look at it under the hood: I've uploaded it as github project

这篇关于将保证金添加到UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆