We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
您可以使用属性字符串设置占位符文本。 通过属性传递所需的颜色:
SwiftUI 使用
SwiftUI
struct ContentView: View { @State var text = "" var body: some View { ZStack(alignment: .leading) { if text.isEmpty { Text("Placeholder").foregroundColor(.red) } TextField("", text: $text) } } }
var myTextField = UITextField(frame: CGRect(x: 0, y: 0, width: 200, height: 30)) myTextField.backgroundColor = .blue myTextField.attributedPlaceholder = NSAttributedString( string: "placeholder text", attributes: [NSForegroundColorAttributeName: UIColor.yellow] )
Swift 3+ 使用以下内容:
Swift 3+
myTextField.attributedPlaceholder = NSAttributedString( string: "placeholder text", attributes: [NSAttributedStringKey.foregroundColor: UIColor.white] )
Swift 4.2 使用以下内容:
Swift 4.2
myTextField.attributedPlaceholder = NSAttributedString( string: "placeholder text", attributes: [NSAttributedString.Key.foregroundColor: UIColor.white] )
The text was updated successfully, but these errors were encountered:
import SwiftUI public struct PlaceholderStyle: ViewModifier { var showPlaceHolder: Bool var placeholder: String public func body(content: Content) -> some View { ZStack(alignment: .leading) { if showPlaceHolder { Text(placeholder) .padding(.horizontal, 15) } content .foregroundColor(Color.white) .padding(5.0) } } } struct ContentView: View { @State var text = "" var body: some View { TextField("", text: $text) .modifier( PlaceholderStyle(showPlaceHolder: text == "", placeholder: "My Placeholder") ) } }
Sorry, something went wrong.
No branches or pull requests
您可以使用属性字符串设置占位符文本。 通过属性传递所需的颜色:
SwiftUI
使用Swift 3+
使用以下内容:Swift 4.2
使用以下内容:The text was updated successfully, but these errors were encountered: