在 swiftUI 中更改视图的背景颜色 [英] Change the background color of a view in swiftUI

查看:93
本文介绍了在 swiftUI 中更改视图的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个简单的表单并更改文本字段的背景颜色,但 Xcode 为我提供了 .background(background: View) 等选项,而不是 .background(Color()).

I want to make a simple form and change the background color of a text field, but Xcode provide me .background(background: View), etc option but not .background(Color()).

推荐答案

Color 符合 View.因此,您可以像使用任何其他 View 一样使用它.您的代码的问题是您添加 cornerRadius inside background 修饰符.应该是这样的:

Color is conformed to View. So you can use it like any other View. The issue with your code is you add cornerRadius inside the background modifier. It should be out like this:

TextField("Title", text: .constant("text"))
    .background(Color.red)
    .cornerRadius(5)

这篇关于在 swiftUI 中更改视图的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆