【发布时间】: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