使用卡创建自定义contentView
问题描述:
使用卡创建自定义内容视图的最佳方式是什么?分配我的内容,以便该卡时使用卡创建自定义contentView
fileprivate var contentView: View!
fileprivate func prepareContentView() {
contentView = View()
let button = RaisedButton(title: "Raised Button", titleColor: .white)
button.pulseColor = .white
button.backgroundColor = Color.blue.base
contentView.layout(button)
.width(150)
.height(44)
.center()
}
然后::现在我做这个
card.contentView = contentView
card.contentViewEdgeInsetsPreset = .wideRectangle3
但是内容视图中显示不出来。
我该如何解决这个问题?
谢谢!
答
问题是当您尝试设置约束时,您的contentView
的框架为.zero
。这就是说你可以设置你的尺寸contentView
,所有的都应该可以工作:
contentView = View(frame: CGRect(x: 0, y: 0, width: 150, height: 44))
一切顺利!