我可以在iOS 12或以上设置stackView的背景彩色
我正在尝试设置StackView的背景色,并且在iOS 13或更新的情况下起作用,但是在iOS 12上,这是一个完全的故障。也许它与Darkmode有关,尽管我不使用任何相关设置。
我试图在viddidload()中设置颜色,也没有用,我有点迷路,我寻找其他类似的问题,没有一个是相同的
viewcode
final class PaymentCashViewCode: UIView, ViewCodeProtocol {
var salesValueComponent: UIStackView = {
let view = UIStackView()
view.backgroundColor = UIColor(named: .greyRhino)
view.isLayoutMarginsRelativeArrangement = true
view.axis = .vertical
return view
}()
}
viewController
class PaymentCashViewController: UIViewController {
var mainView = PaymentCashViewCode()
func setupComponents() {
self.view.addAttrachedSubView(view: mainView)
self.title = viewModel.getViewControllerTitle()
mainView.delegate = self
mainView.setTextFieldDelegate(delegate: self)
mainView.setTextFieldFocus()
}
}
I'm trying to set a backgroundColor of a StackView and it works on iOS 13 or newer, but on iOS 12 it's a complete failure. Maybe it's related to darkMode although I don't use any related settings.
I tried to set the color in VidDidLoad() and it didn't work either, I'm kind of lost, I looked for other similar questions, none were the same
ViewCode
final class PaymentCashViewCode: UIView, ViewCodeProtocol {
var salesValueComponent: UIStackView = {
let view = UIStackView()
view.backgroundColor = UIColor(named: .greyRhino)
view.isLayoutMarginsRelativeArrangement = true
view.axis = .vertical
return view
}()
}
ViewController
class PaymentCashViewController: UIViewController {
var mainView = PaymentCashViewCode()
func setupComponents() {
self.view.addAttrachedSubView(view: mainView)
self.title = viewModel.getViewControllerTitle()
mainView.delegate = self
mainView.setTextFieldDelegate(delegate: self)
mainView.setTextFieldFocus()
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在iOS 14之前,堆栈视图是“非渲染”视图——也就是说,它们只排列子视图。
从 iOS 14 开始,您可以设置背景颜色。
如果您需要早期版本的背景颜色,则需要将堆栈视图嵌入到 UIView 中或将其放置在 UIView 之上
Prior to iOS 14 stack views were "non-rendering" views -- that is, they only arranged their subviews.
Starting with iOS 14 you can set the background color.
If you need a background color for earlier versions, you need to embed the stack view in, or place it on top of, a
UIView