简体   繁体   English

Swift UITableView 中的自动布局标题视图 [已解决]

[英]Swift Autolayout headerview in UITableView [SOLVED]

I'm trying to create a view that has some labels and a UITableView.我正在尝试创建一个包含一些标签和 UITableView 的视图。 First of all i tried to create a UIView => UIScrollview => UIView + UITableView After reading a lot i experienced problems with scrolls, 1 from the UIScrollView and 1 from the UITableView, so i decided to switch to the suggested approach of having: UIView => UITableView with headerview First of all i tried to create a UIView => UIScrollview => UIView + UITableView After reading a lot i experienced problems with scrolls, 1 from the UIScrollView and 1 from the UITableView, so i decided to switch to the suggested approach of having: UIView => UITableView 带标题视图

Scroll works fine but now i have problems with Autolayout.滚动工作正常,但现在我遇到了自动布局的问题。

The header view have 2 labels. header 视图有 2 个标签。 "LeftLabel" and "RightLabel". “左标签”和“右标签”。 The RightLabel should have dynamic height and >= 21 RightLabel 应该具有动态高度并且 >= 21

In code i tried to add a text that won't fit in 1 line and with autolaout label should expand and use 2 o 3 lines to fit the text.在代码中,我尝试添加不适合 1 行的文本,并且使用 autolaout label 应该扩展并使用 2 o 3 行来适应文本。

问题截图

In this screenshot is shown only 1 line.在此屏幕截图中仅显示 1 行。 Constraints are set as:约束设置为: 自动布局

I uploaded the demo proyect to github: https://github.com/Miguel86/UIViewAutolayoutExample/ Scroll works fine, but autolayout of the "headerview" not.我将演示项目上传到 github: https://github.com/Miguel86/UIViewAutolayoutExample/ Scroll 工作正常,但“headerview”的自动布局不行。

Any suggestion of where could be the problem?关于哪里可能出现问题的任何建议?

[UPDATE] Solved using the approach explained in: https://github.com/aunnnn/TableHeaderViewWithAutoLayout [更新]使用以下方法解决: https://github.com/aunnnn/TableHeaderViewWithAutoLayout

From my understanding, problem is that RightLabel isn't going to multiple lines?据我了解,问题是 RightLabel 不会多行? If so: go into storyboard, select the headerview and drag it down so it's Height is longer.如果是这样: go 进入 storyboard, select 标题视图并将其向下拖动,使其高度更长。 I think there just wasn't enough room in the cell for the label to go to 2 lines.我认为单元格中没有足够的空间将 label 到 go 到 2 行。

Try Setting Lines to “0” and Line Breaks To “word wrap”尝试将行设置为“0”并将换行符设置为“自动换行”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM