【问题标题】:How to set section header/footer margins in Eureka without creating custom classes如何在 Eureka 中设置节页眉/页脚边距而不创建自定义类
【发布时间】:2016-05-24 14:39:17
【问题描述】:

我正在使用 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
                }

编辑:我已经尝试了上述方法,但它不起作用。如果你输入一个长字符串,它会向上移动到父节的行中。

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)
}

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

【问题讨论】:

  • 嗨,有效果吗?你有关于它的外观的示例图像吗?欣赏它

标签: swift eureka-forms


【解决方案1】:

我已经通过在每一行中添加表格视图单元格边距......

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

【讨论】:

  • 您好,感谢您的回复。我其实是github线程的作者,节页眉和页脚没有defaultCellSetup。它使用不同的方法来呈现这些 UI 元素。我在 github 上创建了一个新问题,因为 .onSetupView 似乎没有进行任何边距设置。
  • 要向部分页眉/页脚添加边距,您必须实现本自述文件部分中解释的自定义视图:github.com/xmartlabs/Eureka#section-header-and-footer
  • 上面的代码是设置行边距,以防默认表格视图标题符合您的需要。如果您需要对部分标题进行更多自定义,则应该使用自定义视图。
  • 我在使用自定义视图时遇到的问题是我无法让它根据字符串的内容自动调整框架的大小。我想做的只是让字符串环绕并适合屏幕的宽度(减去我设置的边距),并根据显示字符串所需的行数自动调整高度。
  • 我正在向 github 线程发布更新。非常感谢您查看它并让我知道如何将标题字符串传递给它。我已经设法做的所有其他事情! :)
猜你喜欢
  • 2014-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-27
  • 1970-01-01
  • 2011-08-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多