我正在使用Eureka框架,并且最近添加了代码以允许边到边细胞分离器。这样,所有表单元素都需要定义边距,否则它们从屏幕的最左侧开始。
有没有办法像细胞那样调整Section页眉/页脚的左/右边距?我试图避免为每个节/标题标题使用自定义类。
我尝试查看源代码以查看视图是如何创建的,但我没有看到它定义x坐标或左/右边距等的任何地方。我也看不到任何属性可以设定完成这个。
非常感谢任何帮助!
+++ Section(){section in
var footer = HeaderFooterView<UITableViewHeaderFooterView>(.Class)
footer.onSetupView = {view, _, _ in
view.preservesSuperviewLayoutMargins = false
view.layoutMargins.left = 50
view.layoutMargins.right = 50
view.contentView.preservesSuperviewLayoutMargins = false
view.contentView.layoutMargins.top = 10
view.contentView.layoutMargins.left = 50
view.textLabel?.text = "This is a test footer message."
view.textLabel?.layoutMargins.top = 10
view.textLabel?.font = UIFont.preferredFontForTextStyle("Footnote")
}
section.header = HeaderFooterView<ALogoView>(HeaderFooterProvider.Class)
section.footer = footer
}
编辑:我已经尝试了上述内容,但它不起作用。如果你输入一个长字符串,它会向上移动到父节的行。
Edit2:我想出了以下内容
class GenericHeader: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
self.preservesSuperviewLayoutMargins = false
let textView = UILabel()
textView.frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width - 30, height: 20 )
textView.text = "This is a very very very long title, This is a very very very long title, This is a very very very long title, This is a very very very long title, This is a very very very long title, This is a very very very long title Let's add some more stuff here to see how it handles."
textView.numberOfLines = 0
textView.textAlignment = .Justified
textView.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody)
textView.textColor = UIColor(red:0.47, green:0.47, blue:0.49, alpha:1.0)
textView.frame = textView.bounds
textView.sizeToFit()
self.addSubview(textView)
//self.frame = CGRect(x: -15, y: -3, width: textView.bounds.width - 16, height: textView.bounds.height)
self.bounds = CGRect(x: -15, y: -3, width: textView.bounds.width - 16, height: textView.bounds.height)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
我正在以我的形式使用它:
+++ Section() {
$0.header = HeaderFooterView<GenericHeader>(HeaderFooterProvider.Class)
$0.footer = HeaderFooterView<GenericFooter>(HeaderFooterProvider.Class)
}
如何在实例化Header / Footer类时传递一个字符串,这样我就不必用不同的文本编写一百万个不同的类/视图了?
答案 0 :(得分:0)
我已经通过在每行中执行此操作添加了表格视图单元格边距....
TextRow.defaultCellSetup = { cell, row in
cell.preservesSuperviewLayoutMargins = false
cell.layoutMargins.left = 0
cell.contentView.preservesSuperviewLayoutMargins = false
cell.contentView.layoutMargins.left = 50
}
ButtonRow.defaultCellSetup = { cell, row in
cell.preservesSuperviewLayoutMargins = false
cell.layoutMargins.left = 0
cell.indentationLevel = 5
}
调查这个问题,解释一下...... https://github.com/xmartlabs/Eureka/issues/438