gpt4 book ai didi

swift - 使用卡片创建自定义 contentView

转载 作者:行者123 更新时间:2023-11-30 12:04:15 29 4
gpt4 key购买 nike

使用卡片创建自定义内容 View 的最佳方式是什么?现在我这样做:

    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()
}

然后将我的内容 View 分配给卡片时:

card.contentView = contentView
card.contentViewEdgeInsetsPreset = .wideRectangle3

但是内容 View 不会显示。

我该如何解决这个问题?

谢谢!

最佳答案

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

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

祝一切顺利!

关于swift - 使用卡片创建自定义 contentView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46857234/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com