使用卡创建自定义contentView

时间:2017-10-20 20:57:12

标签: swift cosmicmind

使用该卡创建自定义内容视图的最佳方法是什么?现在我这样做:

    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

但内容视图未显示。

我该如何解决这个问题?

谢谢!

1 个答案:

答案 0 :(得分:0)

问题是,在尝试设置约束时,contentView的框架为.zero。也就是说你可以设置contentView的大小,一切都应该有效:

contentView = View(frame: CGRect(x: 0, y: 0, width: 150, height: 44))

一切顺利!

相关问题