首页 > 解决方案 > Change the background color of a view in swiftUI

问题描述

enter image description here

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

标签: iosxcodeswiftuiswift5xcode11

解决方案


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

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

推荐阅读