我刚刚开始进行swift编程,并且我面临着视觉格式限制的困难。我正在尝试制作多个3 x 6行和列的表,并在表的顶部添加和标题。我已经添加了行和列的名称,但它没有按预期(由我)的顺序对齐。下面代码中的问题是:
> addConstraintsWithFormat(format: "H:|-40-[v0][v1][v2]-[v3]-[v4]-|",
> views: cashLabel, pinLabel, idealLabel, houseLabel,
> totalPerPayMethodLabel) is placed in between the rows of
> addConstraintsWithFormat(format: "V:|-[v0(30)]-[v1]-[v2]-[v3]-|",
> views: timePeriodLabel, highBtwLabel, lowBtwLabel, totalPerBtwLabel).此外,cashLabel与pinLabel还有很大差距。当我从视图v0中删除(30)时,包含cashLabel、pinLabel等的行如预期的那样放在其他行(V:)的上方。此外,cashLabel似乎不受H:-40-v0等的影响。
类AccountingCell: UITableViewCell {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setupViews()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
let timePeriodLabel: UILabel = {
let label = UILabel()
label.backgroundColor = UIColor.red
label.text = "Header"
label.translatesAutoresizingMaskIntoConstraints = false
label.textAlignment = .center
return label
}()
let highBtwLabel: UILabel = {
let label = UILabel()
label.text = "high vat"
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
let lowBtwLabel: UILabel = {
let label = UILabel()
label.text = "low vat"
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
let cashLabel: UILabel = {
let label = UILabel()
label.text = "Cash"
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
let pinLabel: UILabel = {
let label = UILabel()
label.text = "Pin"
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
let idealLabel: UILabel = {
let label = UILabel()
label.text = "IDEAL"
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
let houseLabel: UILabel = {
let label = UILabel()
label.text = "House"
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
let totalPerBtwLabel: UILabel = {
let label = UILabel()
label.text = "Totaal"
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
let totalPerPayMethodLabel: UILabel = {
let label = UILabel()
label.backgroundColor = UIColor.red
label.text = "Totaal"
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
func setupViews() {
addSubview(timePeriodLabel)
addSubview(highBtwLabel)
addSubview(lowBtwLabel)
addSubview(cashLabel)
addSubview(pinLabel)
addSubview(idealLabel)
addSubview(houseLabel)
addSubview(totalPerBtwLabel)
addSubview(totalPerPayMethodLabel)
addConstraintsWithFormat(format: "H:|[v0]|", views: timePeriodLabel)
addConstraintsWithFormat(format: "H:|-40-[v0][v1][v2]-[v3]-[v4]-|", views: cashLabel, pinLabel, idealLabel, houseLabel, totalPerPayMethodLabel)
addConstraintsWithFormat(format: "H:|[v0]|", views: timePeriodLabel)
addConstraintsWithFormat(format: "H:|[v0]|", views: highBtwLabel)
addConstraintsWithFormat(format: "H:|[v0]|", views: lowBtwLabel)
addConstraintsWithFormat(format: "H:|[v0]|", views: totalPerBtwLabel)
addConstraintsWithFormat(format: "V:|-[v0(30)]-[v1]-[v2]-[v3]-|", views: timePeriodLabel, highBtwLabel, lowBtwLabel, totalPerBtwLabel)
addConstraintsWithFormat(format: "V:|-[v0]-|", views: cashLabel)
addConstraintsWithFormat(format: "V:|-[v0]-|", views: pinLabel)
addConstraintsWithFormat(format: "V:|-[v0]-|", views: idealLabel)
addConstraintsWithFormat(format: "V:|-[v0]-|", views: houseLabel)
addConstraintsWithFormat(format: "V:|-[v0]-|", views: totalPerPayMethodLabel)
}发布于 2019-03-29 22:41:04
这里的单元格高度是300。此外,您还必须添加更多的UILabels来填充这些表。
addConstraintsWithFormat(format: "H:|[v0]|", views: timePeriodLabel)
addConstraintsWithFormat(format: "H:|-60-[v0(==v1)][v1(==v2)][v2(==v3)][v3(==v4)][v4]-|", views: cashLabel, pinLabel, idealLabel, houseLabel, totalPerPayMethodLabel)
addConstraintsWithFormat(format: "H:|[v0]|", views: timePeriodLabel)
addConstraintsWithFormat(format: "H:|[v0]|", views: highBtwLabel)
addConstraintsWithFormat(format: "H:|[v0]|", views: lowBtwLabel)
addConstraintsWithFormat(format: "H:|[v0]|", views: totalPerBtwLabel)
addConstraintsWithFormat(format: "V:|[v0]-(30)-[v1(==v2)][v2(==v3)][v3]-|", views: timePeriodLabel, highBtwLabel, lowBtwLabel, totalPerBtwLabel)
addConstraintsWithFormat(format: "V:|[v0]-230-|", views: cashLabel)
addConstraintsWithFormat(format: "V:|[v0]-230-|", views: pinLabel)
addConstraintsWithFormat(format: "V:|[v0]-230-|", views: idealLabel)
addConstraintsWithFormat(format: "V:|[v0]-230-|", views: houseLabel)
addConstraintsWithFormat(format: "V:|[v0]-230-|", views: totalPerPayMethodLabel)发布于 2019-04-08 20:42:19
https://stackoverflow.com/questions/55417482
复制相似问题