ios - 为customView设置背景颜色没有效果
问题描述
我有一个customView
在button-tap
. 我的问题是设置.backgroundColor
没有效果,它只是一个clear
背景。
自定义视图:
let wishWishView: WishStackView = {
let v = WishStackView()
v.backgroundColor = .cyan
v.translatesAutoresizingMaskIntoConstraints = false
return v
}()
添加视图按钮:
@objc func addWishButtonTapped(){
self.view.addSubview(self.wishWishView)
wishWishView.centerYAnchor.constraint(equalTo: self.view.centerYAnchor).isActive = true
wishWishView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
}
WishWishView
只是一个简单UIView
的StackView
里面。
解决方案
我的猜测是它是 a UIStackView
,它不支持背景颜色。
您可以在此处阅读有关发生这种情况的更多信息以及可能的解决方法:https ://stackoverflow.com/a/34868367/3992237
推荐阅读
- firebase - 我应该在哪里安装 firebase admin SDK?
- anti-cheat - 防止安卓游戏作弊
- android - 将图像和文本分享到 Twitter 源
- play-billing-library - 在 Android 上的应用购买库中使用 Alternative
- visual-studio-code - 为 VS Code 创建片段 README.md 文件
- python - 我试图在循环时访问 2D 数组的其他部分,但不确定它是如何完成的
- vb.net - VB.NET 表单变量是如何处理的
- react-native - 在反应本机android中进行语音通话时出现错误“不支持WebRTC”
- python - Tkinter.pack() 方法不显示 GUI
- batch-file - 如何创建批处理文件以使用 azcopy 复制数据