我正在使用Eureka框架,最近添加了允许边缘到边缘单元格分隔符的代码。这样,所有表单元素都需要定义一个空白,否则它们将从屏幕的最左侧开始。
是否有类似于单元格的方法来调整节页眉/页脚的左/右边距?我试图避免对每个节/标题使用自定义类。
我试图查看源代码以了解视图是如何创建的,但我看不到它定义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
                }

编辑:我试过上面的方法,但不管用。如果放入一个长字符串,它将向上移动到父节的行中。
伊迪丝2:我想出了以下几点
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)
}

当页眉/页脚类被实例化,这样我就不必用不同的文本编写一百万个不同的类/视图时,如何传递字符串?

最佳答案

我已经通过在每一行中这样做添加了表视图单元格边距…

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

08-06 04:09