简体   繁体   中英

Label being cut off in TableView Xcode10/Swift 4

When creating a new tableview with a single label, the label is being cut off and I cannot seem to increase the size of the cell to accommodate it. I would like to just have a fixed vertical size on the cell. I have tried so many different UI settings nothing seems to work and it seems simple. Here is what it looks like:

在此输入图像描述

Here is what it looks like in design:

在此输入图像描述

You have multiple options to fix this. I have listed them below.

  1. Do not define constant Height constraint for the label. Instead control the layout using top and bottom constraints.
  2. Define constant height constraint for label and play with Autoshrink property. It can be set to Minimum Font Scale and Minimum Font size

您应该尝试使用自动autodimension来确定单元格大小

The solution used was this:

override func viewDidLoad() {
    super.viewDidLoad()
    self.eventCategoryListTableView.rowHeight = UITableView.automaticDimension
}

In addition to this code above you have to make sure to set top, bottom, and height constraints for the label.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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