首页 > 解决方案 > 为customView设置背景颜色没有效果

问题描述

我有一个customViewbutton-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只是一个简单UIViewStackView里面。

标签: iosswiftuiviewbackground-color

解决方案


我的猜测是它是 a UIStackView,它不支持背景颜色。

您可以在此处阅读有关发生这种情况的更多信息以及可能的解决方法:https ://stackoverflow.com/a/34868367/3992237


推荐阅读