简体   繁体   中英

How to change UILabel size if label is truncated in Xcode (Swift)

I am developing a would you rather app and what happens is that some of my questions are too big to fit my label... Is there a way that if there is too much text for the label to fit it will change the size of the label (specifically the height in my case). I've found a couple of answers but:

  1. I am new to Xcode so they are all a bit complex
  2. They are written in Objective-C instead of Swift

Add constraints to your label & set number of lines to 0 & line break to Word wrap .

普通标签

Table View Cell: In the case of tableviewcell add below lines in your viewdidload and apply the settings mentioned in the storyboard screenshot.

tableView.estimatedRowHeight = 85.0
tableView.rowHeight = UITableViewAutomaticDimension

表格视图单元格

只需在UILabel上调用sizeToFit

myLabel.sizeToFit()

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