2017-10-20 70 views
0

使用卡創建自定義內容視圖的最佳方式是什麼?分配我的內容,以便該卡時使用卡創建自定義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 

但是內容視圖中顯示不出來。

我該如何解決這個問題?

謝謝!

回答

0

問題是當您嘗試設置約束時,您的contentView的框架爲.zero。這就是說你可以設置你的尺寸contentView,所有的都應該可以工作:

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

一切順利!