Xcode - Swift - TableViewCell 扩展中的 UILabel
Xcode - Swift - UILabel in TableViewCell Expansion
我在名为 "ScheduleCell" 的自定义 UITableViewCell 中有一个 UILabel,如下所示:
这是 ScheduleCell 的代码:
import UIKit
class ScheduleCell: UITableViewCell {
@IBOutlet weak var titleLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
我希望 tileLabel 基于其文本展开,我希望 ScheduleCell 随之展开。以下是 titleLabel 的属性:
这里是链接到 ScheduleCell 的单元格原型的属性 class:
这里是 ViewController 的一些相关代码:
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 160.0
和
func tableView(tableView: UITableView!,cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
let cell = tableView.dequeueReusableCellWithIdentifier("cell") as! ScheduleCell
cell.backgroundColor = UIColor(rgb: 0xF6FBFE)
cell.titleLabel.text = (Globals.scheduleArr[indexPath.row][3] as! String)
cell.titleLabel.setTranslatesAutoresizingMaskIntoConstraints(false)
return cell
}
"Globals.scheduleArr" 中的所有标题都在一行中,只有一个除外,即 "Jane Richards Grey Reads "杀死一只知更鸟“”。这是 ViewController 在 iOS 模拟器中的样子:
如您所见,标签没有根据需要展开。奇怪的是,当我在每个标题的末尾添加一个“\n”时,标签确实展开了。但是,该单元格似乎没有随着标签展开:
如能帮助解决此问题,我们将不胜感激!
如果要使用UITableViewAutomaticDimension,需要添加Label-ContentViewbottom constraint.
添加新的底部约束并重试!
我在名为 "ScheduleCell" 的自定义 UITableViewCell 中有一个 UILabel,如下所示:
这是 ScheduleCell 的代码:
import UIKit
class ScheduleCell: UITableViewCell {
@IBOutlet weak var titleLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
我希望 tileLabel 基于其文本展开,我希望 ScheduleCell 随之展开。以下是 titleLabel 的属性:
这里是链接到 ScheduleCell 的单元格原型的属性 class:
这里是 ViewController 的一些相关代码:
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 160.0
和
func tableView(tableView: UITableView!,cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
let cell = tableView.dequeueReusableCellWithIdentifier("cell") as! ScheduleCell
cell.backgroundColor = UIColor(rgb: 0xF6FBFE)
cell.titleLabel.text = (Globals.scheduleArr[indexPath.row][3] as! String)
cell.titleLabel.setTranslatesAutoresizingMaskIntoConstraints(false)
return cell
}
"Globals.scheduleArr" 中的所有标题都在一行中,只有一个除外,即 "Jane Richards Grey Reads "杀死一只知更鸟“”。这是 ViewController 在 iOS 模拟器中的样子:
如您所见,标签没有根据需要展开。奇怪的是,当我在每个标题的末尾添加一个“\n”时,标签确实展开了。但是,该单元格似乎没有随着标签展开:
如能帮助解决此问题,我们将不胜感激!
如果要使用UITableViewAutomaticDimension,需要添加Label-ContentViewbottom constraint.
添加新的底部约束并重试!