我正在使用 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)
}
如何在实例化页眉/页脚类时传递一个字符串,这样我就不必用不同的文本编写一百万个不同的类/视图?