【发布时间】:2018-01-31 17:51:15
【问题描述】:
我需要为 UITableViewController 下的 UITableViewCell 设置前导和尾随。
UITableViewCell 的特定类,我在下面添加了代码。
override func layoutSubviews() {
self.frame = CGRect(x: 10.0, y: self.frame.origin.y, width: 390.0, height: self.frame.size.height)
super.layoutSubviews()
}
上面在前导和尾随留下空格。但是当我在 iPhone 5s 和 4 模拟器中测试时出现的问题会导致水平滚动。
由于宽度恒定,我教了这个问题。 所以我从 UITableViewcell 中得到了特定的标签字段宽度并减去了 10.0
我已针对宽度问题尝试了以下代码。但是,没有任何结果。
func setFrame(x: CGFloat, y: CGFloat , width: CGFloat , height: CGFloat ) {
let newX = x.isNaN ? self.frame.origin.x : x
let newY = y.isNaN ? self.frame.origin.y : y
let newWidth = width.isNaN ? self.bounds.size.width : width
let newHeight = height.isNaN ? self.bounds.size.height : height
self.frame = CGRect(x: newX, y: newY, width: newWidth, height: newHeight)
}
override func layoutSubviews() {
let width = (greetingLabel.bounds.size.width - 10.0)
setFrame(x: 5.0, y: 5.0, width:width, height: self.frame.height)
}
我已尝试将所有字段保留在 View 中,但 UI 看起来不太好。
请提供一些关于如何设置 UITableViewCell 的前导和尾随的输入。
我想实现这样的画面:
【问题讨论】:
标签: ios swift uitableview