首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在SwiftUI中更改字体颜色SecureField?

如何在SwiftUI中更改字体颜色SecureField?
EN

Stack Overflow用户
提问于 2020-02-19 20:59:31
回答 1查看 297关注 0票数 0

我有自定义的Textfield。

代码语言:javascript
复制
CustomTextField(placeholder: Text("Login").foregroundColor(.white),
                                        text: $login)
                                        .background(Color(red: 0/255, green: 174/255, blue: 180/255))
                                        .opacity(0.5)
                                        .cornerRadius (29)
                                        .frame (height: 50)
                                        .font(.system(size: 40))
                                        .foregroundColor(Color.white)

但是我需要为Securefield创建这个。我怎么能做到这一点?用于自定义文本字段的表单

代码语言:javascript
复制
struct CustomTextField: View {
var placeholder: Text
@Binding var text: String
var editingChanged: (Bool)->() = { _ in }
var commit: ()->() = { }

var body: some View {
    ZStack(alignment: .leading) {
        if text.isEmpty { placeholder }
        TextField("", text: $text, onEditingChanged: editingChanged, onCommit: commit)
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-19 22:00:49

你是说这个吗?

代码语言:javascript
复制
struct ContentView : View {

    @State var login : String = "aha"

    @State var password : String = "aha"

    var body : some View {

        CustomTextField(placeholder: Text("Login").foregroundColor(.white),
                        text: $login, password: $password)
            .background(Color(red: 0/255, green: 174/255, blue: 180/255))
            .opacity(0.5)
            .cornerRadius (29)
            .frame (height: 50)
            .font(.system(size: 40))
            .foregroundColor(Color.white)
    }
}

struct CustomTextField: View {
    var placeholder: Text
    @Binding var text: String
    var editingChanged: (Bool)->() = { _ in }
    var commit: ()->() = { }
    @Binding var password : String

    var body: some View {
        ZStack(alignment: .leading) {
            if text.isEmpty { placeholder }
           // TextField("", text: $text, onEditingChanged: editingChanged, onCommit: commit)
            SecureField(text, text: $password) {

            }
        }
    }
}
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60300945

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档